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

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

I really don't know why it is wrong(Java Scrip)
Послано Hufeng Zhou 17 авг 2010 20:04
Hi, I tried to use java to solve this problem but failed, yet do not know where is the bug,
I have pasted the source code here, wish someone can help me out. I am very very grateful.

public class ReversRoot1001 {
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new FileReader("ReversRoot1001.txt"));

        Vector<Integer> record = new Vector<Integer>();

        String line;
        while((line = br.readLine())!=null){
            Scanner sc = new Scanner(line);
            int a = sc.nextInt();
            record.add(a);
//            if(sc.hasNext()){
//                int b = sc.nextInt();
//                //int c = sc.nextInt();
//                record.add(b);
//            }
            while(sc.hasNext()){
                int b = sc.nextInt();
                record.add(b);
            }
        }

        for(int i = record.size();i<record.size();i--){
            System.out.println(record.get(i));
        }
        br.close();
    }

}
Re: I really don't know why it is wrong(Java Scrip)
Послано Moonstone 17 авг 2010 20:56
Use standart input/output. And don't use Scanner - it's very slow.

Look:

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

String readToken() throws IOException { // reads the token; to read a full line use in.readLine()
    while (tok == null || !tok.hasMoreTokens()) {
        tok = new StringTokenizer(in.readLine());
    }
    return tok.nextToken(); // sometimes it's better to use nextToken(String) method here
}

int readInt() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary
    return Integer.parseInt(readToken());
}

And, finally, don't forget to write out.flush() at the end of your program!

Edited by author 17.08.2010 21:26
Re: I really don't know why it is wrong(Java Scrip)
Послано Hufeng Zhou 18 авг 2010 06:20
Moonstone Thank you so much for your help.
I am very grateful!

Edited by author 18.08.2010 06:21