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 1585. Penguins

Why Crash?
Posted by Georgeek 5 Jul 2011 14:40
import java.util.Scanner;


public class Example {

    private static int n;
    private static String[] penguin;
    private static int[] myCount = {1, 1, 1};

    public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            n = scanner.nextInt();
            if(n>=1 && n<=1000){
                scanner = new Scanner(System.in);
                penguin = new String[n];
                for (int i = 0; i < n; i++) {
                    penguin[i] = scanner.nextLine();
                    if (penguin[i].equals("Emperor Penguin")) {
                        myCount[0]++;
                    }else if (penguin[i].equals("Little Penguin")) {
                        myCount[1]++;
                    }else if (penguin[i].equals("Macaroni Penguin")) {
                        myCount[2]++;
                    }
                }
                if(myCount[0]>myCount[1]){
                    if(myCount[0]>myCount[2]){
                        System.out.println("Emperor Penguin");
                    }else{
                        System.out.println("Macaroni Penguin");
                    }
                }else if(myCount[1]>myCount[2]){
                    System.out.println("Little Penguin");
                }else{
                    System.out.println("Macaroni Penguin");
                }

            }
    }

}