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 }
  • 相关阅读:
    Jquery 图片走马灯效果原理
    jquery实现跑马灯效果(一)
    jQuery实现网页放大镜功能
    JavaScript仿淘宝实现放大镜效果的实例
    jquery实现放大镜简单方法
    jQuery实现放大镜效果
    小白jquery横向菜单弹出菜单制作
    转载 Log4j2在WEB项目中配置
    Struts2关于命名空间的例子
    转载关于struts命名空间的一则报警
  • 原文地址:https://www.cnblogs.com/niithub/p/5817304.html
Copyright © 2011-2022 走看看