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!

Help in Java 1.7
Posted by Axmadjon 5 Jun 2014 16:20
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Scanner;

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

    private static Scanner s = new Scanner(System.in);
    static int n = 0;

    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 {

        String input;

        input = s.nextLine();
        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--;
                }
            }
        }
    }

}