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.

InputInput 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. 
OutputFor 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
常规解法:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
char str[10000][20],k[100];
int n;
while (cin >> n && n != 0)
{
int a[10000] = { 0 };
int mark = 0;
int max = 0,ko = 0;
for (int i = 0; i < n; i++)
{
int flag = 0;
cin >> k;
for (int j = 0; j < mark; j++)
{
if (strcmp(str[j], k)==0)
{
a[j]++; flag = 1;
if (a[j] > max)
{
max = a[j];
ko = j;
}
break;
}
}
if (!flag)
strcpy(str[mark++], k);
}
cout << str[ko] << endl;
}
return 0;
}

  map的解法(水题):

 #include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
int ballnum;
while (cin >> ballnum && ballnum != )
{
string temp,ko;
int bigger = ;
map<string, int> balloon; for (int i = ; i<ballnum; i++)
{
cin >> temp;
balloon[temp]++;
if (balloon[temp] > bigger)
{
bigger = balloon[temp];
ko = temp;
}
}
cout << ko << endl; }
return ;
}

最新文章

  1. 关于mvc5+EF里面的db.Entry(model).State = EntityState.Modified报错问题
  2. oracle asm 概念
  3. [codevs1155][KOJ0558][COJ0178][NOIP2006]金明的预算方案
  4. FastDFS安装、配置、部署
  5. Java跟Javac,package与import
  6. HW2.22
  7. XML中SystemID和PublicID的区别
  8. kiddouk/redisco
  9. 【zzulioj 2135】 这里是天堂!
  10. I - Intersection HDU - 5120(圆环相交面积)
  11. 三步法搞定CTF中的SQL注入题型
  12. docker的核心概念和安装
  13. 使用Mybatis时mybatis-config.xml配置中&quot;configuration&quot; 的内容必须匹配 (.....)解决方案
  14. Hyper-v 虚拟机 关闭服务
  15. Linux Makefile 中的陷阱【转】
  16. zabbix监控短信息接口是否正常
  17. aliyun服务器ecs被ddos后无法被zabbix-server监控的处理
  18. UIScrollView的一些关系
  19. python+jenkins 构建节点环境编译器配置问题
  20. BZOJ4280 : [ONTAK2015]Stumilowy sad

热门文章

  1. mysql 原理 ~ LRU 算法与buffer_pool
  2. shiro--《跟我学Shiro》网友学习系列
  3. EL知识点总结
  4. 根据传入的文件名称动态从moglifs图片服务器拿到pdf文档并在线浏览
  5. 集合-HashSet
  6. pythonのSocket
  7. listView从底部回到顶部代码实现
  8. camera理论基础和工作原理【转】
  9. python下载mp4 同步和异步下载支持断点续下
  10. oracle 会话 解锁