1004Let the Balloon Rise

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
struct node
{
    string st;int cnt;
    node(string s,int k=1):st(s),cnt(k){}
    node(){}
    bool operator<(const node&x)const{return cnt<x.cnt;}
    bool operator==(const node&x)const{return x.st==st;}
};
int main()
{
    int n;
    while(cin>>n,n)
    {
        string s;
        vector<node>ball;
        vector<node>::iterator it;
        for(int i=0;i<n;++i)
        {
            cin>>s;
            it=find(ball.begin(),ball.end(),node(s));
            if(it==ball.end())ball.push_back(node(s));
            else it->cnt++;
        }
        it=max_element(ball.begin(),ball.end());
        cout<<it->st<<endl;
    }
}

你可能感兴趣的:(1004Let the Balloon Rise)