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 }
  • 相关阅读:
    Axis2创建WebService服务端接口+SoupUI以及Client端demo测试调用
    python 网络爬虫 scapy 下载 论坛帖子链接和标题
    scrapy抓中文,保存csv文件乱码解决方法
    python 3 map函数用法
    HTML基础信息笔记
    css提取数据2个常用方法
    Python3 scrapy 新手命令
    Python3.0 urllib request自己第一成功做出爬虫
    python geopandas读取保存文件中文属性乱码
    arcmap中dissolve时ERROR000210
  • 原文地址:https://www.cnblogs.com/niithub/p/5817304.html
Copyright © 2011-2022 走看看