Let the Balloon Rise

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

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
5
green
red
blue
red
red
3
pink
orange
pink
0
 
Sample Output
red
pink
 
Author
WU, Jiazhi
 
Source
分析:STL大法好啊,本题要求最大的气球数,可以用到STL标准库中的map<string,int>来保存,当map的first插入一个string的时候,map的second++,就可以统计出具体的string的个数了,然后遍历找到最大值就可以了!
下面给出AC代码:
 #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int>ballon;
int n;
string str;
while(cin>>n&&n)
{
ballon.clear();
while(n--)
{
cin>>str;
ballon[str]++;
}
int maxn=;
string maxcolor;
map<string,int>::iterator it;
for(it=ballon.begin();it!=ballon.end();it++)
{
if(it->second>maxn)
{
maxn=(*it).second;
maxcolor=(*it).first;
}
}
cout<<maxcolor<<endl;
}
return ;
}

最新文章

  1. EF多对多更新报错(TableNoTracking引发的bug)
  2. Spring框架学习一
  3. 转:JQuery选择器
  4. 从0开始学Swift笔记整理(二)
  5. seajs学习笔记
  6. android 打包错误
  7. JavaScript学习笔记(十二) 回调模式(Callback Pattern)
  8. 从3D Studio Max导入物体 Importing Objects From 3D Studio Max
  9. 《C和指针》读书笔记 第5章-操作符和表达式
  10. OSPF + LVS ,突破LVS瓶颈 (转)
  11. 【数学】HDU 5753 Permutation Bo
  12. js判断上传文件的类型和大小
  13. MyEclipse8.5自动生成注册码
  14. C语言中结构体參数变量的传递
  15. 两个linux之间拷贝文件及文件夹
  16. JasperReport 中踩过的坑
  17. js面向对象编程 ---- 系列教程
  18. Emulator: glTexImage2D: got err pre :( 0x502 internal 0x1908 format 0x1908 type 0x1401
  19. CSS-带尖角的对话框
  20. SettingsHBuilder

热门文章

  1. ASP.NET Core使用SkiaSharp实现验证码
  2. 使用Node.js搭建一个本地服务器
  3. Mac 终端—不同文件不同颜色显示,提示文字
  4. js变量提升与函数提升
  5. 豹哥嵌入式讲堂:ARM开发中有用的文件(1)- source文件
  6. ActiveMQ (二) 常用配置简介
  7. PHP-CGI进程占用过多CPU
  8. Windows下使用OpenSSL生成自签证书
  9. K:java中的hashCode和equals方法
  10. 程序猿的日常——HashMap的相关知识