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

help in java
Posted by ankur parashar 11 Oct 2008 01:05
import java.util.Scanner;

public class Reverseroot
{
public static void main(String args[])
{
  solve();
}
public static void solve()
{
 Scanner s=new Scanner(System.in);

  while(s.hasNext())
       {
   double t=s.nextDouble();
       solve();
   double n=(double) Math.sqrt(t);
   System.out.printf("%.4f\n",n);
      }

}
}

what is wrong in my solution ..
could somebody give me the solution of this problum in C
Did you try your solution for the sample?
Posted by Vladimir Yakovlev (USU) 11 Oct 2008 01:51
Re: Did you try your solution for the sample?
Posted by ankur parashar 11 Oct 2008 03:40
i tried it on my linux machine and it is giving me right solution..may b problem due to exceed limti
i tried it using BIGDECIMAL also
here is my code but it is giving a crash ....

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Scanner;
import java.io.StreamTokenizer;

public class Reverseroot
{
public static void main(String args[])
{
  solve();
}
public static void solve()
{
 Scanner s=new Scanner(System.in);
  while(s.hasNext())
       {
    BigInteger b=new BigInteger(s.nextLine());
        solve();
  double x=Math.sqrt(b.doubleValue());
   System.out.println(BigDecimal.valueOf(x).setScale(4, RoundingMode.HALF_UP));
      }

}
}

frnds i need help
Re: help in java
Posted by Davor 10 Mar 2009 01:38
Put this while loop in try/catch block. I had the same problem, judge reported crash on my program. That fixed it. Seams to me that .hasNext() is the problem.

And eliminate recursion, for gods sake!! You have one stack frame for every number, and u have 256k of numbers. Its incredibly inefficient.