0

This is a problem set

This is my realization it works, but i get wrong answer on 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 に答える