A. World Football Cup

A. World Football Cup
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard 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, wherename1name2 — names of the teams; num1num2 (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<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 100000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

struct node{
int sc;
int goal;
int diff;
string ss;
}p[maxn];
bool cmp(node a,node b){
if(a.sc==b.sc){
if(a.diff==b.diff){
return a.goal>b.goal;
}
return a.diff>b.diff;
}
return a.sc>b.sc;
}
bool cmp1(node a,node b){
return a.ss<b.ss;
}
map
<string,int>mp;

int main()
{

//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
mp
.clear();
string s;
for(int i=0;i<n;i++){
cin
>>s;
mp
[s]=i;
p
[i].ss=s;
}
int a,b;
char c;
for(int j=1;j<=n*(n-1)/2;j++){
cin
>>s>>a>>c>>b;
int k=0;
for(int i=0;i<=s.size();i++){
if(s[i]=='-'){
k
=i;break;
}
}
string s1,s2;
s1
=s.substr(0,k);
s2
=s.substr(k+1,s.size()-k-1);
int t1=mp[s1];
int t2=mp[s2];
if(a>b){
p
[t1].sc+=3;
p
[t1].goal+=a;
p
[t1].diff+=(a-b);
p
[t2].diff+=b-a;
p
[t2].goal+=b;
}
else if(a<b){
p
[t2].sc+=3;
p
[t2].goal+=b;
p
[t2].diff+=(b-a);
p
[t1].diff+=a-b;
p
[t1].goal+=a;
}
else if(a==b){
p
[t1].sc++;
p
[t2].sc++;
p
[t1].goal+=a;
p
[t2].goal+=b;
}
}
/*
int i=0;
map<string,int>::iterator it=mp.begin();
for(;it!=mp.end();++it){
i++;
p[i].first=it->second;
p[i].second=it->first;
//cout<<p[i].second<<" "<<p[i].first<<endl;
}
*/

sort
(p,p+n,cmp);

sort
(p,p+n/2,cmp1);

for(int i=0;i<n/2;i++)
cout
<<p[i].ss<<" ";
cout
<<endl;
}
return 0;
}

你可能感兴趣的:(A. World Football Cup)