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

Обсуждение задачи 1213. Тараканы!

why crash on this in java:while (input.equals("#")!=true)
Послано dracularKing 27 июн 2006 20:56
who can tell me
Re: why crash on this in java:while (input.equals("#")!=true)
Послано Vladimir Yakovlev (USU) 28 июн 2006 00:48
Your program crashes on another line.

Didn't you try to run your program on sample input?
Re: why crash on this in java:while (input.equals("#")!=true)
Послано dracularKing 28 июн 2006 09:42
i tried on my pc, i managed to have it runned through
i know that's all because im not familiar with the online java judge environment, but i just cannot get any feedback infomation from the email system, how does it come?

here's my codes, i really dont know where and how

import java.io.*;

public class Application
{
    public static void main(String[] args) throws IOException
    {
        new Application().run();
    }

    StreamTokenizer in;
    PrintWriter out;
    static int n = 0;

    void run() throws IOException
    {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(
            System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }

    void solve() throws IOException
    {

        String input = null;
        String[] strArray = new String[30];

        while (true)
        {
            input = getString();

            if (input.equals("#"))
            {
                break;
            }
            else
            {
                saveItToArray(strArray, input);
            }
        }

        checkOutIdentical(strArray);

        System.out.println(n - 1);
    }

    private static String getString() throws IOException
    {
        BufferedReader keyboard =
            new BufferedReader(new InputStreamReader(System.in));
        String input;

        input = keyboard.readLine();
        return (input);
    }

    void saveItToArray(String[] strArray, String input)
    {
        boolean isDash = false;
        for (int i = 0; i < input.length(); i++)
        {
            if (input.charAt(i) == '-')
            {
                strArray[n++] = input.substring(0, i);
                strArray[n++] = input.substring(i + 1, input.length());

                isDash = true;
                break;
            }
            else
            {
                isDash = false;
            }
        }

        if (!isDash)
        {
            strArray[n++] = input;
        }

    }

    void checkOutIdentical(String[] strArray)
    {
        int count = 0;
        count = n;
        for (int i = 1; i < count; i++)
        {
            for (int j = i - 1; j >= 0; j--)
            {
                if (!strArray[i].equals(" ") && !strArray[j].equals(" ") &&
                    strArray[i].equals(strArray[j]))
                {
                    strArray[i] = " ";
                    n--;
                }
            }
        }
    }
}
Re: why crash on this in java:while (input.equals("#")!=true)
Послано Vladimir Yakovlev (USU) 28 июн 2006 12:13
getString() is wrong!!!
BufferedReader(new InputStreamReader(System.in)) reads whole input during the first run of getString(), but you use only first line of it