NEFU要崛起——第17场 A

           http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=18824#problem/A         
                                                                                                            A. World Football Cup
                                                                   time limit per test2 secondsmemory limit per test
                                                                64 megabytesinputtandard inputoutputstandard output

Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:

  • the final tournament features n teams (n is always even)
  • the first n / 2 teams (according to the standings) come through to the knockout stage
  • the standings are made on the following principle: for a victory a team gets 3 points, for a draw — 1 point, for a defeat — 0 points. In the first place, teams are ordered in the standings in decreasing order of their points; in the second place — in decreasing order of the difference between scored and missed goals; in the third place — in the decreasing order of scored goals
  • it's written in Berland's Constitution that the previous regulation helps to order the teams without ambiguity.

You are asked to write a program that, by the given list of the competing teams and the results of all the matches, will find the list of teams that managed to get through to the knockout stage.

Input

The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) / 2 lines describe the held matches in the format name1-name2 num1:num2, where name1, name2 — names of the teams; num1, num2 (0 ≤ num1, num2 ≤ 100) — amount of the goals, scored by the corresponding teams. Accuracy of the descriptions is guaranteed: there are no two team names coinciding accurate to the letters' case; there is no match, where a team plays with itself; each match is met in the descriptions only once.

Output

Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.

Sample test(s)
Input
4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3
Output
A
D
Input
2
a
A
a-A 2:1
Output
a
 
 
这道题暴露了一直不重视字符串处理的弊端
 
代码:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct Team{
	string name;
	int fen;
	int jing;
	int jizong;
    	
}team[100];

int cmp(Team x,Team y)
{
	if(x.fen!=y.fen)
	return x.fen>y.fen;
	else if(x.jing>y.jing)
	return x.jing>y.jing;
	else
	return x.jizong>y.jizong;
}

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>team[i].name;				
	}
	for(int i=0;i<n;i++)
	{
		team[i].fen=team[i].jizong=team[i].jing=0;
	}
	int m=n*(n-1)/2;
	string str,str1,str2;
	int a,b;
	char ch;
	for(int i=0;i<m;i++)
	{
		cin>>str;
		str1=str.substr(0,str.find('-'));
		str2=str.substr(str.find('-')+1);
		cin>>a>>ch>>b;
		
		for(int i=0;i<n;i++)
		{	
	    	if(team[i].name==str1)
	    	{
	    		
	    		if(a>b)
	    		 team[i].fen+=3;
    		    else if(a==b)
	    		 team[i].fen+=1;
	    		 
	    		 team[i].jing+=a-b;
	    		 team[i].jizong+=a;	    		 
	    		 
	    	}
	    	if(team[i].name==str2)
	    	{
	    		if(b>a)
	    		team[i].fen+=3;
	    	    else if(a==b)
	    		 team[i].fen+=1;
				 
				 team[i].jing=b-a;	    		 
	    		 team[i].jizong+=b;	    		
	    	}		
	     }
	}
	
	sort(team,team+n,cmp);

	 string zidian[100];
	 for(int i=0;i<n/2;i++)
	  {
  		zidian[i]=team[i].name;
  
  
  	}
	  sort(zidian,zidian+n/2);
	  for(int i=0;i<n/2;i++)
	  {
  		cout<<zidian[i]<<endl;
  	}
	 
	 
	 
	 
	return 0;
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值