poj2643Election

18 篇文章 0 订阅
6 篇文章 0 订阅
Election
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3846 Accepted: 1824

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

3
Marilyn Manson
Rhinoceros
Jane Doe
Family Coalition
John Smith
independent
6
John Smith
Marilyn Manson
Marilyn Manson
Jane Doe
John Smith
Marilyn Manson

Sample Output

Rhinoceros

Source

 
 
answer:
#include"iostream"
#include"map"
#include"string"
using namespace std;

int main(int argc, char* argv[])
{
 	map<string,string>party;
	map<string,int>score;
	party.clear();
	score.clear();
	int n,m;
	int i,j,max,flag;
	max=0;
	flag=0;
	string s1,s2,name,temp;
	cin>>n;
	getchar();//吃掉回车,注意
	for(i=0;i<n;i++)
	{
		getline(cin,s1);
		getline(cin,s2);
		party[s1]=s2;
	}
	cin>>m;
	getchar();//吃掉回车,注意
	for(j=0;j<m;j++)
	{
		getline(cin,name);
		score[name]++;
		if(score[name]>max)
		{
			max=score[name];
			temp=party[name];
			flag=1;
		}
		else if(score[name]==max)
				flag=0;
	}
	if(flag==1)
		cout<<temp<<endl;
	else
		cout<<"tie"<<endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值