1001.Reverse Root
?
1001.?Reverse?Root
Time?limit:?2.0?second
Memory?limit:?64?MB
The?problem?is?so?easy,?that?the?authors?were?lazy?to?write?a?statement?for?it!
Input
The?input?stream?contains?a?set?of?integer?numbers?Ai?(0?≤?Ai?≤?1018).?The?numbers?are?separated?by?any?number?of?spaces?and?line?breaks.?A?size?of?the?input?stream?does?not?exceed?256?KB.
Output
For?each?number?Ai?from?the?last?one?till?the?first?one?you?should?output?its?square?root.?Each?square?root?should?be?printed?in?a?separate?line?with?at?least?four?digits?after?decimal?point.
Sample
input | output |
?1427??0??? ? ???876652098643267843? 5276538 ? ? | 2297.0716 936297014.1164 0.0000 37.7757 ? |
?
代碼:
using?System;
using?System.Globalization;
?
publicclassReverseRoot
{
privatestaticvoid?Main()
????{
NumberFormatInfo?nfi?=?NumberFormatInfo.InvariantInfo;
string[]?input?=?Console.In.ReadToEnd().Split(
newchar[]?{?'?',?'\t',?'\n',?'\r'?},?StringSplitOptions.RemoveEmptyEntries);
for?(int?i?=?input.Length?-?1;?i?>=?0;?i--)
????????{
double?root?=?Math.Sqrt(double.Parse(input[i],?nfi));
Console.WriteLine(string.Format(nfi,?"{0:F4}",?root));
????????}
????}
}
?
總結:
1.學習了C#中的屬性定義,并查找資料了解Console.In屬性為什么還有方法ReadToEnd(),ReadToEnd()后面還有Split方法。
2.使用TextReader?類定義的輸入方法ReadToEnd?(?)和String.Split(?)方法?
3.了解NumberFormatInfo類及其成員
4.學習了輸出格式
?
1.屬性是一種類成員,它將字段和訪問字段的方法組合在一起。屬性不一定是值類型,它也可以是一個類的實例。所以說,屬性是有類型的,這個類型有這個方法,就可以了!具體可參考http://bbs.csdn.net/topics/80284324和http://zhidao.baidu.com/question/320769258.html。ReadToEnd()方法返回的是string對象,Split()方法是String類的方法,故可在ReadToEnd()后面還有Split方法。個人總結,是先執行Console.In.ReadToEnd(),再將返回的String對象Split(),這也是input是數組的原因.
?
2.方法:string?ReadToEnd()?是TextReader類定義的輸入方法,功能是讀取數據流中從當前位置到結尾的所有字符并將它們作為一個字符串返回。String.Split()返回包含此實例中的子字符串(由指定?Char?或?String?數組的元素分隔)的?String?數組,詳細可搜MSDN。
?
3.NumberFormatInfo類,根據區域性定義設置數值格式以及如何顯示數值,詳細可搜MSDN。
?
4.學習了String.Format()方法格式化數據
?
轉載于:https://blog.51cto.com/gilbertbog/1213245
總結
以上是生活随笔為你收集整理的1001.Reverse Root的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ios 开发框架原始雏形 01
- 下一篇: ifconfig vs ip: comp