zoj 2104 Let the Balloon Rise(map映照容器的应用)

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2104

题目描述:

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

5
green
red
blue
red
red
3
pink
orange
pink
0


Sample Output

red
pink

 1 /*问题 统计每种颜色气球的个数并输出
 2 解题思路 问题本身很简单,使用结构体数组也可以做,这里提供一种map映照容器的做法,效率更高
 3 具体做法:每读入一个字符串,先搜索该键值的是否存在,存在修改映照数据,不存在插入,最后遍历找到映照数据
 4 最大即可*/ 
 5 #include <cstdio>
 6 #include <map>
 7 #include <string>
 8 using namespace std;
 9 
10 int main()
11 {
12     int n;
13     char s[20];
14     string colo; 
15     map<string,int> m; 
16     map<string,int>::iterator it,max;
17     while(scanf("%d",&n), n != 0)
18     {
19         while(n--)
20         {
21             scanf("%s",s);
22             colo=s;
23             it=m.find(colo); 
24             if(it != m.end())
25                 m[colo]++;
26             else
27                 m[colo]=1;
28         }
29         
30         max=m.begin();
31         for(it=m.begin(); it != m.end();it++){
32             if(it->second > max->second)
33             //if((*it).second > (*max).second) 
34                 max=it;
35         }
36         printf(max->first.c_str());//转换 
37         putchar('\n');
38         m.clear();
39     }
40     return 0;
41 }

 

转载于:https://www.cnblogs.com/wenzhixin/p/8543700.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值