ZOj 2104——Let the Balloon Rise

来源:互联网 发布:清华 软件硕士 编辑:程序博客网 时间:2024/05/16 12:37
老师在上课的时候讲过这道题,不过当时做这道题时还是纠结了许久,那时stl不熟,老是想着用数组,去重很麻烦,学了STL后,用map就简单多了。
code :
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
map < string, int >m;
string a, k;
int n, max;
while (cin >> n && n) {
m.clear();
while (n--) {
cin >> a;
m[a]++;
}
map < string, int >::iterator it;
max = 0;
for (it = m.begin(); it != m.end(); it++) {
if ((*it).second > max) //遍历寻找最大的气球数
      {
max = (*it).second;
k = (*it).first;
}
}
cout << k << endl;
}
return 0;
}

0 0
原创粉丝点击