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

Problem at the Java
Posted by Meni Packeou 22 Oct 2007 18:29
My code timeLimitexit  9-test.I not understanding where is mistak.Help me programmists.Down my code.



import java.util.Scanner;
import java.io.IOException;
import java.io.PrintWriter;
public class File{
 public static void main(String[] args)throws IOException{
     Scanner sc=new Scanner(System.in);
     PrintWriter pw=new PrintWriter(System.out);
     double[] a=new double[150000];
     int n=0;
     while(sc.hasNext())
      a[n++]=sc.nextDouble();
     while(n>0)
      pw.println(String.format("%.4f",Math.sqrt(a[--n])));
      pw.close();
    }
}
Re: Problem at the Java
Posted by arm5556 28 Jun 2008 22:27
String.format("%.4f",Math.sqrt(a[--n])) is a bottleneck for your solution. Let try using BigDecimal and when you want to format number to 4 digits just call setScale.
Re: Problem at the Java
Posted by Meni Packeou 14 Aug 2008 14:45
Thank you!!!