HDU 1004

来源:互联网 发布:平湖市行知中学陈晓霞 编辑:程序博客网 时间:2024/05/09 07:16

STL  map


#include <iostream>#include <cstdio>#include <map>#include <cstring>using namespace std;map<string,int> mp;int main(){    string ans,tmp;    int maxn,n;    while(cin >> n && n)    {        maxn = 0;        mp.clear();        while(n--)        {            cin >> tmp;            mp[tmp]++;            if(mp[tmp]>maxn)            {                ans = tmp;                maxn = mp[tmp];            }        }        cout << ans << endl;    }    return 0;}


0 0