Animal statistics enhanced Edition
Time Limit: 3000 MS | memory limit: 150000 KB
Difficulty: 4
Description
There are a large number of species in the virgin forest of the beautiful daxing'anling district. The list of unrecorded primitive animals is included in the animal data provided by the surveyors. Scientists want to determine which animal in the forest has the largest number, but because the data is too large, scientists can't stand it at last. They want to ask your ACMer for help.
Input
In the first line, enter the number of animal names N (1 <= N <= 4000000). In the next N lines, enter N strings to indicate the name of the animal (the length of the string cannot exceed 10, all strings are lowercase letters and only one group of test data is available ).
Output
Output the names and quantities of the most animals among them, and separate them with spaces (data ensures that there are no more than two types of animals ).
Sample Input
10
Boar
Pig
Sheep
Gazelle
Sheep
Sheep
Alpaca
Alpaca
Marmot
Mole sheep
/** You can use the dictionary tree * or use HashMap to access the water */import java. util. hashMap; import java. util. extends; public class Main {public static void main (String [] args) {extends input = new loads (System. in); int n = input. nextInt (); HashMap <String, Integer> map = new HashMap <String, Integer> (); int sum = 0; String str = ""; while (n --> 0) {String s = input. next (); if (map. get (s) = null) {map. put (s, 1); if (sum <1) {sum = 1; str = s ;}} else {int num = map. get (s) + 1; map. put (s, num); if (sum <num) {sum = num; str = s ;}} System. out. println (str + "" + sum );}}