[Timus] 1585 Penguins

Problem statement is here: http://acm.timus.ru/problem.aspx?space=1&num=1585

Keep a count of each of the types of penguins and you are all set.

 

public void solve(int testNumber, InputReader in, OutputWriter out) {
        int[] counter = new int[3];

        int n = in.nextInt();

        while (n-- > 0) {
            String penguin = in.readLine();

            if (penguin.equalsIgnoreCase("Emperor Penguin")) {
                counter[0]++;
            } else if (penguin.equalsIgnoreCase("Macaroni Penguin")) {
                counter[1]++;
            } else if (penguin.equalsIgnoreCase("Little Penguin")) {
                counter[2]++;
            }
        }

        out.println(counter[0] > counter[1] ? (counter[0] >
                                               counter[2] ? "Emperor " +
                                                            "Penguin" :
                                                       "Little Penguin") :
                            (counter[1] >
                             counter[2] ? "Macaroni Penguin" : "Little " +
                                                               "Penguin"));

    }

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.