1001.Reverse Root
1001.ReverseRoot
Timelimit:2.0second
Memorylimit:64MB
Theproblemissoeasy,thattheauthorswerelazytowriteastatementforit!
Input
TheinputstreamcontainsasetofintegernumbersAi(0≤Ai≤1018).Thenumbersareseparatedbyanynumberofspacesandlinebreaks.Asizeoftheinputstreamdoesnotexceed256KB.
Output
ForeachnumberAifromthelastonetillthefirstoneyoushouldoutputitssquareroot.Eachsquarerootshouldbeprintedinaseparatelinewithatleastfourdigitsafterdecimalpoint.
Sample
input
output
14270
876652098643267843
5276538
2297.0716
936297014.1164
0.0000
37.7757
代码:
usingSystem;
usingSystem.Globalization;
publicclassReverseRoot
{
privatestaticvoidMain()
{
NumberFormatInfonfi=NumberFormatInfo.InvariantInfo;
string[]input=Console.In.ReadToEnd().Split(
newchar[]{'','\t','\n','\r'},StringSplitOptions.RemoveEmptyEntries);
for(inti=input.Length-1;i>=0;i--)
{
doubleroot=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.方法:stringReadToEnd()是TextReader类定义的输入方法,功能是读取数据流中从当前位置到结尾的所有字符并将它们作为一个字符串返回。String.Split()返回包含此实例中的子字符串(由指定Char或String数组的元素分隔)的String数组,详细可搜MSDN。
3.NumberFormatInfo类,根据区域性定义设置数值格式以及如何显示数值,详细可搜MSDN。
4.学习了String.Format()方法格式化数据
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。