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

Wrong answer Java
Posted by gaaral 11 Jan 2012 11:14
My code:
BS))))
Isn't it because in (1) round answer?
Could you help me?

Edited by author 12.01.2012 00:24
Re: Wrong answer Java
Posted by gaaral 11 Jan 2012 23:29
The same with this code:

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ReSqrt {


    public static void main(String[] args) {

        String st = null, st1 = "";

        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            while ((st = br.readLine()) != null){
                st1 = st1 + st;
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        st1 = st1.trim();
        st1 = st1.replaceAll("\\s{1,}", "\u0020");
        String[] arrSt = st1.split(" ");
        int sizeArr = arrSt.length;

        float outSqrt;

        for (int i = sizeArr - 1; i>=0; i--){
            outSqrt = Float.parseFloat(arrSt[i]);
            outSqrt = (float)Math.sqrt(outSqrt);
            System.out.printf("%.4f", outSqrt);
            System.out.println();
        }
    }
}
Re: Wrong answer Java
Posted by Noob 12 Jan 2012 00:15
NEVER use float, use double instead
Re: Wrong answer Java
Posted by gaaral 12 Jan 2012 00:23
thx
I did, and I got "Memory limit exceeded"))

new code:


        String st = null, st1 = "";

        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            while ((st = br.readLine()) != null){
                st1 = st1 + st+" ";
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        st1 = st1.trim();
        st1 = st1.replaceAll("\\s{1,}", "\u0020");
        String[] arrSt = st1.split(" ");
        int sizeArr = arrSt.length;

        double outSqrt, dSt;

        for (int i = sizeArr - 1; i>=0; i--){
            dSt = Long.parseLong(arrSt[i]);
            outSqrt = Math.sqrt(dSt);
            System.out.printf("%.4f", outSqrt);
            System.out.println();


        }
Re: Wrong answer Java
Posted by Noob 12 Jan 2012 00:51
String concatenation is slow
Regexps are slow

ALWAYS use code below to read input data

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer tok = null;

String readString() throws IOException {
    while (tok == null || !tok.hasMoreTokens()) {
        tok = new StringTokenizer(in.readLine());
    }
    return tok.nextToken();
}

int readInt() throws IOException {
    return Integer.parseInt(readString());
}

double readDouble() throws IOException {
    return Double.parseDouble(readString());
}
Re: Wrong answer Java
Posted by gaaral 12 Jan 2012 08:36
Even if it has \r\n???

Got it!!!

Edited by author 12.01.2012 09:25