ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1001. Обратный корень

Wrong answer Java
Послано gaaral 11 янв 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
Послано gaaral 11 янв 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
Послано Noob 12 янв 2012 00:15
NEVER use float, use double instead
Re: Wrong answer Java
Послано gaaral 12 янв 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
Послано Noob 12 янв 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
Послано gaaral 12 янв 2012 08:36
Even if it has \r\n???

Got it!!!

Edited by author 12.01.2012 09:25