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

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

Where is the end of the file in Java?
Послано Skulty 23 мар 2007 22:33
If there is a variable number of line breaks, how can you know when it is the end of the file?!
I read all the posts about this and I've read the FAQ and yet I can't get the loop (the one where I ask for input) to stop when the input is over (because the program doesn't know it is over). How do you do this?
Re: Where is the end of the file in Java?
Послано dimozzz 23 мар 2007 23:16
If you use BufferedReader, then readLine() return null String.
Example:
BufferedReader in = new BuffereReader(new InputStreamReader(System.in));
String temp = in.readLine();
while(temp != null){
    temp = in.readLine();
}
.
.
.
.

Edited by author 23.03.2007 23:18
Re: Where is the end of the file in Java?
Послано Skulty 24 мар 2007 19:04
Thanks for the help, now I can make it up to the test#9. Unfortunatelly I can't manage to make my solution go fast enough and always exceed the time limit... I used almost all the tips I read in the FAQ an forum and still it works real slow... I think it's the printf... Is there any way around it?
Re: Where is the end of the file in Java?
Послано dimozzz 24 мар 2007 20:42
You musn't use Scanner, because it's too slow.
It's part of my solution for this problem:

public class Solution {
    public static void main(String[] args)throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
.
.
.

        String s = in.readLine();
        StringTokenizer st = new StringTokenizer(s);
        while(s != null){
            while(!st.hasMoreTokens()){
                s = in.readLine();
                if(s == null)break;
                st = new StringTokenizer(s);
            }
            if(s == null)break;
            n = Long.parseLong(st.nextToken());
        }
.
.
.
.
    }
}

Edited by author 24.03.2007 20:43