zoukankan      html  css  js  c++  java
  • 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

    inputoutput
     1427  0   
    
       876652098643267843 
    5276538
      
       
    2297.0716
    936297014.1164
    0.0000
    37.7757

    译文:

    输入:

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

    输出:

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

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

    第一次code:

     1 import java.math.BigDecimal;
     2 import java.math.RoundingMode;
     3 import java.util.Scanner;
     4 
     5 public class Main
     6 { 
     7     public static void main(String[] args) 
     8     { 
     9         Scanner input = new Scanner(System.in);
    10         long[]a = new long[1000000000];
    11         int i;
    12         for (i=0; input.hasNext(); i++)  
    13         {
    14              a[i] = input.nextLong();
    15         } 
    16         for(i--;i>-1;i--)
    17         {
    18                         /**
    19                         *   Math.sqrt()  :  对数据求平方
    20                         *   BigDecimal适用于大型数据计算,精确度高
    21                         */
    22             BigDecimal   b   =   new   BigDecimal(Math.sqrt(a[i]));  
    23             System.out.println(b.setScale(4,RoundingMode.HALF_UP).toString());
    24         }
    25     }
    26 }
    27     

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

    /*

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

    */

     1 import java.math.BigDecimal;
     2 import java.math.RoundingMode;
     3 import java.util.Scanner;
     4 
     5 public class Main
     6 { 
     7     public static void main(String[] args) 
     8     { 
     9         Scanner input = new Scanner(System.in);
    10         int n =input.nextInt();
    11         run();
    12     }
    13     public static void run()
    14     {
    15         Scanner input = new Scanner(System.in);
    16         long[]a = new long[n];
    17         int i;
    18         for (i=0; i<n; i++)  
    19         {
    20              a[i] = input.nextLong();
    21         } 
    22         for(i--;i>-1;i--)
    23         {
    24             BigDecimal   b   =   new   BigDecimal(Math.sqrt(a[i]));  
    25             System.out.println(b.setScale(4,RoundingMode.HALF_UP).toString());
    26         }
    27     }
    28 }
  • 相关阅读:
    迭代器生成器
    eval()
    【剑指offer】调整数组数字位置
    【剑指offer】二进制中1的个数
    【剑指offer】斐波那契数列非递归求解第N项
    【剑指offer】两个栈实现队列
    【剑指offer】逆序输出链表
    【剑指offer】字符串替换
    【剑指offer】规则二维数组查找
    Java转型
  • 原文地址:https://www.cnblogs.com/niithub/p/5817304.html
Copyright © 2011-2022 走看看