0

这是一个问题集

这是我意识到它有效,但我在 acm.timus.ru 上得到了错误的答案

import java.io.PrintWriter;
import java.util.Scanner;

public class SqrtBack{

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int count = 0;
        PrintWriter out = new PrintWriter(System.out);

        long[] arr = new long[131072];
        while(in.hasNextLong()){
            arr[count] = in.nextLong();
            count++;
        }

        for(int i = arr.length-1; i>=0; i--){
            System.out.printf("%.4f%n", (Math.sqrt(arr[i])));

        }
        out.flush();
    }
} 
4

1 回答 1

5

You are always printing 131072 values even though the input could be fewer... Change your loop to:

for(int i = count - 1; i >= 0; i--) ...

Note: Always try with the sample data when doing problems like this. In this case you would see the problem directly..

于 2012-04-24T08:45:16.210 回答