ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

Why wrong answer? Java
Posted by Arderun 19 Apr 2016 19:42
Sample numbers have different value of math.sqrt() in last digit. Why? This task is not so big level for hidden problem.

 sample result:
2297.0716
936297014.1164
0.0000
37.7757

my result:
2297.0715
936297024.0000
0.0000
37.7757

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

public class AlgorithmTAsk {

    public static void main(String[] arg){

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        ArrayList<Float> f = new ArrayList<Float>();

        while (in.hasNextLong()) {
            f.add((float) Math.sqrt(in.nextLong()));
        }

        for(int i = f.size()-1;i>=0;i--){
            out.printf("%8.6f\n",f.get(i));

        }

        out.flush();
    }
}

Edited by author 19.04.2016 19:45
Re: Why wrong answer? Java
Posted by ToadMonster 20 Apr 2016 00:19
Try double instead of float
Help me out here
Posted by Shiva S Dixith 24 Aug 2016 22:47
import java.util.Scanner;
import java.text.DecimalFormat;
import java.lang.StringBuffer;
import java.lang.Math;
public class Timus2{
    public static void main(String[] args){
        Scanner S = new Scanner(System.in);
        DecimalFormat df = new DecimalFormat("#.0000");
        StringBuffer result = new StringBuffer();
        while(S.hasNext()){
            result.append(df.format(Math.sqrt(S.nextDouble())) + "\n");
        }
        S.close();
        System.out.println(result);
    }
}
Re: Help me out here
Posted by ToadMonster 25 Aug 2016 00:40
1) Any advantages of using "StringBuffer result"?
Is it really faster then just print result line by line?

2) Show here expected output, your program output, compare.