
题解
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int main() {
std::ios::sync_with_stdio(false);
int N, max;
string ans;
string color;
while (cin >> N && N) {
map<string, int>mp;
max = 0;
for (int i = 0; i < N; i++) {
cin >> color;
if (!mp.count(color)) {
mp.insert(pair<string, int>(color, 1));
}
else {
mp[color]++;
}
}
map<string, int>::iterator iter;
for (iter = mp.begin(); iter != mp.end(); iter++) {
if (iter->second > max) {
max = iter->second;
ans = iter->first;
}
}
cout << ans << endl;
}
return 0;
}
本文提供了一个解决HDU1004 Let the Balloon Rise问题的C++实现方案,通过使用标准模板库(map)来统计每种颜色气球出现的次数,并找出出现次数最多的气球颜色。
608

被折叠的 条评论
为什么被折叠?



