fjnu 1571 Election

Description

Canada has a multi-party system of government. Each candidate is generally associated with a party, and the party whose candidates win the most ridings generally forms the government. Some candidates run as independents, meaning they are not associated with any party. Your job is to count the votes for a particular riding and to determine the party with which the winning candidate is associated.

Input

The first line of input contains a positive integer n satisfying 2 <= n <= 20, the number of candidates in the riding. n pairs of lines follow: the first line in each pair is the name of the candidate, up to 80 characters; the second line is the name of the party, up to 80 characters, or the word "independent" if the candidate has no party. No candidate name is repeated and no party name is repeated in the input. No lines contain leading or trailing blanks.
The next line contains a positive integer m <= 10000, and is followed by m lines each indicating the name of a candidate for which a ballot is cast. Any names not in the list of candidates should be ignored.

Output

Output consists of a single line containing one of:
The name of the party with whom the winning candidate is associated, if there is a winning candidate and that candidate is associated with a party.
The word "independent" if there is a winning candidate and that candidate is not associated with a party.
The word "tie" if there is no winner; that is, if no candidate receives more votes than every other candidate.

Sample Input


Sample Output



Source:

#include
<iostream>
#include
<map>
#include
<string>
using namespace std;

map
<string,string> mp1;
map
<string,int> mp2;
int n,m;
string name[50];

void input()
{
    
char  s1[100],s2[100];
    
for(int i=1;i<=n;i++)
    
{
        gets(s1);
        gets(s2);
        mp1[
string(s1)]=s2;
        name[i]
=string(s1);
    }

}


void count()
{
    scanf(
"%d ",&m);
    
char s[100];
    
for(int i=1;i<=m;i++)
    
{
        gets(s);
        mp2[
string(s)]++;
    }

}


int findmax()
{
    
int max1=-1,max2=-1;
    
int pos,i,t;
    
for(i=1;i<=n;i++)
    
{
        t
=mp2[name[i]];
        
if(t>=max1)
        
{
            max1
=t;
            pos
=i;
        }

    }

    
for(i=1;i<=n;i++)
    
{
        t
=mp2[name[i]];
        
if(t>=max2&&i!=pos)
        
{
            max2
=t;
        }

    }

    
if(max1==max2) return 0;
    
else return pos;
}


int main()
{
//    freopen("fjnu_1571.in","r",stdin);
    scanf("%d ",&n);
    input();
    count();
    
int t=findmax();
    
if(t==0) cout<<"tie"<<endl;
    
else
    
{
        cout
<<mp1[name[t]]<<endl;
    }

    
return 0;
}









 
阅读更多
个人分类: ☆ACM 解题报告☆
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭