IBM技术俱乐部主席竞选
时间限制(普通/Java) :
1000 MS/ 3000 MS 运行内存限制 : 65536 KByte
总提交 : 632 测试通过 : 249
总提交 : 632 测试通过 : 249
比赛描述
今天IBM技术俱乐部举行主席竞选,你的任务是统计谁是得票最多的候选人。
输入
输入数据包含多组测试案例。
每组测试案例由N(0<N<1000)开头,N表示投票总数,后续N行每行包含一个参加主席竞选的候选人代号(多达18个字母或数字),表示得到有效选票。
一个测试案例的N=0表示输入的结束,无需处理。
输出
对于每个测试用例,把得票最多的候选人名字打印在单独一行上。每个测试案例都仅有一种候选得票是最多的。
样例输入
6
young
CS
showtyt
Titan
young
zt
4
M07000315
sed
B07031006
M07000315
0
样例输出
young
M07000315
题目来源
南京邮电大学计算机学院首届ACM程序设计大赛(2009)
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(void){
int N=0,i=0,max_num=0;
string str,candicate;
map<string,int> word_count;
map<string,int>::const_iterator map_it;
while(cin>>N && N){
max_num = 0;
word_count.clear();
for(i=0;i<N;++i){
cin>>str;
++word_count[str];
}
for(map_it=word_count.begin();map_it!=word_count.end();++map_it){
if(map_it->second>max_num){
max_num = map_it->second;
candicate = map_it->first;
}
}
cout<<candicate<<endl;
}
}