温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

1001.Reverse Root

发布时间:2020-04-15 12:20:27 来源:网络 阅读:528 作者:Gilbert_ 栏目:编程语言

 

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/80284324http://zhidao.baidu.com/question/320769258.htmlReadToEnd()方法返回的是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()方法格式化数据

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI