题解 AT899 【投票】
管理你让我怎么排版?
- STL!!!
- map是本题的通常解法,也是很简单的
- 每次将候选人的票数++,用迭代器遍历一遍,找到最大值以及答案
代码:
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
map<string, int> mp;
int main()
{
int n;
cin >> n;
while(n--)
{
string s;
cin >> s; mp[s]++;
}
int max = -1;
string ans = "";
for(map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it)
{
if(it -> second > max)
{
max = it -> second;
ans = it -> first;
}
}
cout << ans << endl;
return 0;
}

浙公网安备 33010602011771号