hdu 1004 Let the Balloon Rise map的应用

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1004

 

map的用法,第一次看见map还能这么用

#include<iostream>
#include<map>
#include<string>
using namespace std;
int n;
string s;

int main()
{
    while (cin >> n, n){
        map<string, int>a;
        map<string, int>::iterator b;
        for (int i = 0; i < n; i++){
            cin >> s;
            a[s]++;
        }
        b = a.begin();
        int ans=0;
        string res;
        for (; b != a.end(); b++){
            if (b->second >ans){
                ans = b->second;
                res = b->first;
            }
        }
        cout << res << endl;
    }
    return 0;
}
View Code

 

posted @ 2019-03-09 18:57  looeyWei  阅读(84)  评论(0编辑  收藏  举报