Timus Online Judge 1001. Reverse Root

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

译文:

输入:

输入一个整数数组,这个数组中每个整数的取值范围为0<= Ai <=10的18次方。这些数字被一些空格和换行符分隔。输入的内存限制为256KB。

输出:

倒序输出数组的平方根。每个平方根结果保留最后四位小数。

==========================

第一次code:

 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.Scanner;

 public class Main
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);
         long[]a = new long[1000000000];
         int i;
         for (i=0; input.hasNext(); i++)
         {
              a[i] = input.nextLong();
         }
         for(i--;i>-1;i--)
         {
                         /**
                         *   Math.sqrt()  :  对数据求平方
                         *   BigDecimal适用于大型数据计算,精确度高
                         */
             BigDecimal   b   =   new   BigDecimal(Math.sqrt(a[i]));
             System.out.println(b.setScale(4,RoundingMode.HALF_UP).toString());
         }
     }
 }
     

-------------------------------------我是万恶的分割线---------------------------------------------------------------------------------------------------------

/*

题目稍微修改一下,首先输入一个数,定义数组大小,然后倒序输出该数组的平方根。

*/

 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.Scanner;

 public class Main
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);
         int n =input.nextInt();
         run();
     }
     public static void run()
     {
         Scanner input = new Scanner(System.in);
         long[]a = new long[n];
         int i;
         for (i=0; i<n; i++)
         {
              a[i] = input.nextLong();
         }
         for(i--;i>-1;i--)
         {
             BigDecimal   b   =   new   BigDecimal(Math.sqrt(a[i]));
             System.out.println(b.setScale(4,RoundingMode.HALF_UP).toString());
         }
     }
 }
上一篇:[URAL]刷题记录表


下一篇:第8章 用户模式下的线程同步(4)_条件变量(Condition Variable)