您的位置:首页 > 其它

hdu1004(map容器)

2016-04-17 09:25 363 查看
#include <iostream>

#include <stdio.h>

#include <string.h>

#include <algorithm>

#include <map>

using namespace std;

int n,maxnum;

string a,maxstr;

map<string, int> m;

int main()

{

    while(cin >> n&&n){

        m.clear();

        for(int i =0; i < n; i++){

            cin >> a;

            m[a]++;

        }

        maxnum=0;

        map<string, int>::iterator iter;

        for(iter = m.begin();iter != m.end();iter++){

            if(maxnum < iter->second){

                maxnum=iter->second;

                maxstr=iter->first;

            }

        }

        cout <<maxstr<<endl;

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: