第十七场

来源:互联网 发布:head first Java翻译者 编辑:程序博客网 时间:2024/04/27 19:31

Description

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 followingn 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 followingn· (n - 1) / 2 lines describe the held matches in the formatname1-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 Input

Input
4ABCDA-B 1:1A-C 2:2A-D 1:0B-C 1:0B-D 0:3C-D 0:3
Output
AD
Input
2aAa-A 2:1
Output
a
#include<iostream>#include<cstdio>#include<algorithm>#include<string.h>#include<map>using namespace std;struct node{char name[33];int s;int d;int g;}Node[100];map<string,int> Map;int cmp(node A,node B){if (A.s == B.s){if (A.d == B.d){return A.g > B.g;}return A.d > B.d;}return A.s > B.s;}int cmp1(node A, node B){return strcmp(A.name,B.name) <= 0;}int main(){    int n,t,i;    char ss[66];    string temp;while (scanf("%d",&n)!=EOF){Map.clear();for (int i=0; i<n; i++){scanf("%s",ss);Node[i].s= 0;Node[i].d= 0;Node[i].g= 0;strcpy(Node[i].name,ss);Map[ss]=i;}for (t=0; t<(n*(n-1)/2); t++){int x,y,j;            string te,st;            string temp1="",temp2="";            x=y=0;            cin>>te>>st;            for(i=0; i<te.size(); i++)            {                if(te[i]=='-')                    break;                temp1+=te[i];            }            for(j=i+1; j<te.size(); j++)            {                temp2+=te[j];            }            for(i=0; i<st.size(); i++)            {                if(st[i]==':')                    break;                x=(x+st[i]-'0')*10;            }            x/=10;            for(j=i+1; j<st.size(); j++)            {                y=(y+st[j]-'0')*10;            }            y/=10;if (x > y){Node[Map[temp1]].s += 3;Node[Map[temp1]].d+= x-y;Node[Map[temp1]].g += x;Node[Map[temp2]].s += 0;Node[Map[temp2]].d += y-x;   Node[Map[temp2]].g += y;}else if (x == y){Node[Map[temp1]].s+= 1;Node[Map[temp1]].d+= x-y;Node[Map[temp1]].g += x;Node[Map[temp2]].s+= 1;Node[Map[temp2]].d+= y-x;Node[Map[temp2]].g+= y;}else{Node[Map[temp1]].s+= 0;Node[Map[temp1]].d+= x-y;Node[Map[temp1]].g+= x;Node[Map[temp2]].s+= 3;Node[Map[temp2]].d+= y-x;Node[Map[temp2]].g+= y;}}sort (Node,Node+n,cmp);sort (Node,Node + n/2,cmp1);for (int i = 0; i < n/2; i++){   cout<<Node[i].name<<endl;}}}