zoj 1854 Election

/*
zoj_1854    字符串处理
说实话,这题也太恶心了。。数字后面是有可能有多个空格的。。
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;
map <string,string>mp;
map <string,int>num;

int main()
{
    int n,m,i,maxi;
    string a,b;
    map <string,int>::iterator it;
    bool flag;
    while( cin>>n )
    {
        while( getchar()!='\n' ) continue;
        for( i=0;i<n;i++ )
        {
            getline( cin,a );
            getline( cin,b );
            mp[a]=b;
            num[a]=0;
        }
        cin>>m;
        while( getchar()!='\n' ) continue;
        for( i=0;i<m;i++ )
        {
            getline( cin,a );
            if( mp[a].size()!=0 )
                num[a]++;
        }
        maxi=0;    flag=false;
        for( it=num.begin();it!=num.end();it++ )
        {
            if( it->second>maxi )
            {
                maxi=it->second;
                a=it->first;
                flag=true;
            }
            else if( it->second==maxi )
            {
                flag=false;
            }
        }
        if( flag )  cout<<mp[a]<<endl;
        else cout<<"tie\n";
        mp.clear();
        num.clear();
    }
    return 0;
}

你可能感兴趣的:(String,iterator,ini)