hdu1004Let the Balloon Rise

#include <iostream>

#include <cstdio>

#include <cstring>

#include <map>

#include <algorithm>



using namespace std;

//	2013-08-31 15:48:21	Accepted	1004	0MS	372K	956 B	G++	Achiberx

int main()

{

    int n;

    string t;

    map<string, int> mymap;

    map<string, int>::iterator it;

    while(scanf("%d", &n) != EOF && n) {

        mymap.clear();

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

            cin >> t;

            it = mymap.find(t);

            if(it != mymap.end()) {

                it->second ++;

            }

            else {

                mymap[t] = 1;

               // printf("%d\n", mymap[t]);

            }

        }

        string res;

        int maxv = 0;

        for(it = mymap.begin(); it != mymap.end(); ++it) {

            if(it->second > maxv) {

                maxv = it->second;

                res = it->first;

            }

        }

        cout << res << endl;

    }

    return 0;

}

/**

5

green

red

blue

red

red

3

pink

orange

pink

0

**/

你可能感兴趣的:(HDU)