Let the Balloon Rise

来源:互联网 发布:南风知我意txt免费下载 编辑:程序博客网 时间:2024/05/19 13:24

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 121311    Accepted Submission(s): 47673


Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you.
 

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.
 

Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
 

Sample Input
5greenredblueredred3pinkorangepink0
 

Sample Output
redpink
 很水。。。。。
import java.util.Scanner;import java.util.HashMap;public class Main {public static void main(String[] args) {// TODO 自动生成的方法存根Scanner in=new Scanner(System.in);int n;String ans;while((n=in.nextInt())>0){HashMap<String,Integer> s=new HashMap<String,Integer>();for(int i=0;i<n;i++){String temp=in.next();if(s.containsKey(temp)){s.put(temp,s.get(temp)+1);}else{s.put(temp, 1);}}ans="";int cnt=0;for(HashMap.Entry<String,Integer>e:s.entrySet()){if(e.getValue()>cnt){cnt=e.getValue();ans=e.getKey();}}System.out.println(ans);}}}


原创粉丝点击