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 }
  • 相关阅读:
    Java jni字符串转换
    Python读取PE文件(exe/dll)中的时间戳
    深度学习word embedding猜测性别初探
    闪存内容汇编(截止20170405)
    如何自动化安装字体(命令行批量)
    如何分析进程的内存占用问题
    Python print报ascii编码异常的靠谱解决办法
    Linux界面自动化测试框架不完全汇总
    Qt实现同步(阻塞式)http get等网络访问操作
    基于第三方开源库的OPC服务器开发指南(4)——后记:与另一个开源库opc workshop库相关的问题
  • 原文地址:https://www.cnblogs.com/niithub/p/5817304.html
Copyright © 2011-2022 走看看