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 1213. Cockroaches!

who can tell me
Vladimir Yakovlev (USU) Re: why crash on this in java:while (input.equals("#")!=true) [2] // Problem 1213. Cockroaches! 28 Jun 2006 00:48
Your program crashes on another line.

Didn't you try to run your program on sample input?
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--;
                }
            }
        }
    }
}
Vladimir Yakovlev (USU) Re: why crash on this in java:while (input.equals("#")!=true) // Problem 1213. Cockroaches! 28 Jun 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