ZOJ Problem Set

来源:互联网 发布:mac系统的ipa文件 编辑:程序博客网 时间:2024/06/13 13:48

Let the Balloon Rise

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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



Author: WU, Jiazhi
Source: Zhejiang Provincial Programming Contest 2004


题目大意:

输入n个气球颜色,输出颜色最多的


解题思路:

用STL模板中的map(key, value)来做很容易,key为颜色,当同一种颜色重复时,让value计数,然后将value值最大的那个key输出即可。


AC:

#include <cstdio>#include <string>#include <map>#include <iostream>using namespace std;int main(){int n;while(cin>>n && n){map <string, int> Balloon;string s;for(int i=0; i<n; i++){cin>>s;Balloon[s]++;}int iMax = 0;map <string, int>::iterator point, loc; //定义迭代器for(point=Balloon.begin(); point!=Balloon.end(); point++){if(iMax<point->second)//first指的是key,second指的是第二个value{iMax = point->second;loc = point;}}cout<<loc->first<<endl;}return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 网贷小象优品上被别人冒用了怎么办 当你和老人产生冲突时该怎么办 百度网盘会员到期后容量怎么办 一个人不停的给你发视频聊天怎么办 被谋杀后的身后事应该怎么办 社保交了五年被单位辞退怎么办 桅子花叶子变黄叶杆蔫怎么办 薄荷养的都黄了干掉了怎么办 被烟草局没收的烟要是假烟怎么办 干了10年工程不想干了怎么办 在服务行业当服务员干不下去怎么办 高中生晚上偷着跑出去玩怎么办 货车高速忘记过安全检查站了怎么办 u盘上的文件名称乱码了怎么办 暖气管掉进去一点水泥渣怎么办 暗埋在瓷砖下的暖气管漏水怎么办 埋在瓷砖下面的水管漏水怎么办 埋在瓷砖下的水管漏水怎么办 水压太大把水管撑坏了怎么办 无效安装包与系统不兼容怎么办 圣空法师持五戒范戒了怎么办 美航空要是不改中国台湾标志怎么办 淘宝买的东西质量有问题怎么办 天猫618长达20天c店怎么办 新开的淘宝店铺没有生意怎么办 淘宝账号登陆限制用不了花呗怎么办 闲鱼买家签收后说是空盒怎么办 在咸鱼卖东西买家恶意退货怎么办 淘宝联系不上买家物流返回怎么办 换了支付宝绑定手机号退款怎么办啊 淘宝评价错了追评评价错了怎么办 淘宝给客户退款后还给差评怎么办 淘宝账号处于下单保护状态怎么办 淘宝卖家物流单号写错了怎么办 有个人给我发直播消息怎么办 网贷申请多了现在秒拒怎么办 顺丰快递寄的瓜果坏了怎么办 淘宝退货快递公司填错了怎么办 不小心把淘宝账号注销了怎么办 腾讯视频会员开通一个月贵怎么办 微交易买美国指数输了四千块怎么办