-
Notifications
You must be signed in to change notification settings - Fork 2
/
Zoo.java
29 lines (24 loc) · 809 Bytes
/
Zoo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Success in 0.14s
import java.util.*;
public class Zoo{
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int nList = 1;
int nItems = reader.nextInt();
reader.nextLine();
while(nItems != 0){
TreeMap<String, Integer> zoo = new TreeMap<String, Integer>();
for(int i = 0; i < nItems; i++){
String[] wholeAnimal = reader.nextLine().split(" ");
String animal = wholeAnimal[wholeAnimal.length - 1].toLowerCase();
zoo.put(animal, (zoo.containsKey(animal) ? zoo.get(animal) : 0) + 1);
}
System.out.printf("List %d:\n", nList++);
// for(Map.Entry<String, Integer> animal : zoo.entrySet())
// System.out.printf("%s | %d\n", animal.getKey(), animal.getValue());
nItems = reader.nextInt();
reader.nextLine();
}
reader.close();
}
}