Let the Balloon Rise

 1 import java.util.HashMap;
 2 import java.util.Map;
 3 import java.util.Scanner;
 4 
 5 import javax.swing.text.html.HTMLDocument.Iterator;
 6 
 7 public class Main{
 8     public static void main(String args[]) {
 9         Scanner sc=new Scanner(System.in);
10         while(sc.hasNext()) {
11             int n=sc.nextInt();
12             if(n==0) {
13                 break;
14             }
15             Map<String,Integer> map=new HashMap<String,Integer>();
16             for(int i=0;i<n;i++) {
17                 String key=sc.next();
18                 if(!map.containsKey(key)) {
19                     map.put(key, 1);
20                 }
21                 else {
22                     int temp=map.get(key);
23                     map.put(key, ++temp);
24                 }
25             }
26             int max=Integer.MIN_VALUE;
27             String color="";
28             java.util.Iterator<String> it=map.keySet().iterator();
29             while(it.hasNext()) {
30                 String theKey=it.next();
31                 int theValue=map.get(theKey);
32                 if(max<theValue) {
33                     color=theKey;
34                     max=theValue;
35                 }
36             }
37             System.out.println(color);
38         }
39     }
40 }

转载于:https://www.cnblogs.com/DixinFan/p/9083501.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值