題目描述
衆所周知,在打ACM比賽的時候,隊伍只要通過了一個題,志願者們就會送過來相對應顏色的氣球 (志願者小姐姐好漂亮QAQ)
現在剛剛進行完一場ACM比賽,PIPI拿到了所有的氣球顏色,但是他想知道哪個題通過的人最多,你能告訴PIPI通過隊伍最多的題所對應的氣球顏色嗎?
輸入
輸入包含多組測試用例。
對於每一個測試樣例,第一行輸入一個數字n (0<n<=1000),代表氣球的數目。
以下n行每一行是一個長度不超過15爲字符串s,代表氣球的顏色。
輸入以0爲結尾,對應的樣例無需處理。
輸出
對於每組樣例,輸出顏色數最多氣球的顏色。輸出保證唯一解~
樣例輸入
5 green red blue red red 3 pink orange pink 0
樣例輸出
red pink
AC Code
#include<iostream>
#include<cmath>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const double PI=acos(-1);
const double EPS=1e-6;
const int MAXN=1000+10;
int a[MAXN];
map<string, int> mp;
int main(){
freopen("C:\\Users\\Ambition\\Desktop\\in.txt","r",stdin);
int n;
string s;
while(~scanf("%d",&n)&&n){
mp.clear();
for(int i=0; i<n; ++i){
cin>>s;
++mp[s];
}
map<string, int>::iterator it;
int maxTimes=0;
string maxColor;
for(it=mp.begin(); it!=mp.end(); ++it){
if(it->second>maxTimes) {
maxTimes=it->second;
maxColor=it->first;
}
}
cout<<maxColor<<endl;
}
return 0;
}