ZOJ 2524 Football Match

Football Match

Time Limit: 2 Seconds      Memory Limit: 32768 KB

Today football has become the most popular sport all over the world. Many countries have their own football league matches. And the FIFA wants to hold a great league match which could contains all the clubs throughout the world. It is difficult to rank so many teams just by hand. So they come to you for help.

The rules of ranking are: 
1. A team will get 3 points when they win a match, 1 point when get a draw, 0 point when lost. 
2. Teams are ranked by their total points first. If two teams have the same points, the team who get the more "goal difference" ranks higher. "Goal difference" for a team is equal to the total number of balls they goal minus those they lost. 
3. If two teams have both the same points and the same "goal difference", ranking them by their name alphabetically.

Input

The input contains many cases. The beginning of each case is a num m (m<=10000), which is the number of matches. The following m lines each give a score of a match. The format is: 
Team_name1 score1:score2 Team_name2
The length of team name is no more than 20 characters and the scores are less than 100. You may assume that every team in the league has taken part in at least one match.

Output

For each case output a ranking table, each team a line. The format of each line is 
Id Nm w d l Pt Gd
"Id" is the index of the team starting from 1. "Nm" is the name of the team. "w", "d" and "l" respectively is the total number of matches the team win, draw and lost. "Pt" is the points of the team. And "Gd" is the team's goal difference. 
Use a single blank to separate all cases.

Sample Input

4
Liverpool 1:0 ManchesterU
ManchesterU 3:0 Leeds
Arsenal 2:2 Liverpool
Leeds 1:5 Arsenal
6
RealMadrid 3:2 ACMilan
ZJGreenCity 3:2 RealMadrid
ACMilan 1:4 ZJGreenCity
RealMadrid 0:0 ZJGreenCity
ACMilan 2:0 RealMadrid
ZJGreenCity 3:3 ACMilan

Sample Output

1 Arsenal 1 1 0 4 4
2 Liverpool 1 1 0 4 1
3 ManchesterU 1 0 1 3 2
4 Leeds 0 0 2 0 -7

1 ZJGreenCity 2 2 0 8 4
2 ACMilan 1 1 2 4 -2
3 RealMadrid 1 1 2 4 -2

这是一道水题。题意:有巨大数量的足球队比赛,规则如下,赢得队得3分,平的队得1分,输得队得0分,让你按照他所给出的要求排名(注意格式即可),首先按照得分,如果得分相同则按净胜球数量,如果净胜球数量也相同,则按照字母表顺序排列。然后输出球队 胜的场数,平的场数,输的场数,总得分和净胜球数。题意止!

 

下面贴代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <queue>
 7 #include <cmath>
 8 using namespace std;
 9 const int MN=10005;
10 struct team
11 {
12     char name[25];
13     int w,d,l,pt,wins,losts,gd;
14 }result[MN];
15 void calcu(char a[],int i,int p,int q)
16 {
17     strcpy (result[i].name,a);
18     if(p>q) result[i].w++;
19     else if(p==q) result[i].d++;
20     else result[i].l++;
21     result[i].wins+=p;
22     result[i].losts+=q;
23 }
24 bool cmp(struct team a1,struct team a2)
25 {
26     if(a1.pt!=a2.pt) return a1.pt>a2.pt;
27     else if(a1.gd!=a2.gd) return a1.gd>a2.gd;
28     else return strcmp(a1.name,a2.name)<0;
29 }
30 int main()
31 {
32     int n,q,p,i,j;
33     char a[25],b[25];
34     int flag=0;
35     while(scanf("%d",&n)!=EOF){
36         if(flag)    printf("\n");
37         flag=1;
38         int num=0;
39         memset(result,0,sizeof(result));
40         for(i=0;i<n;i++){
41             scanf("%s%d:%d%s",a,&p,&q,b);
42             for(j=0;j<num;j++)
43             {
44                 if(strcmp(a,result[j].name)==0)
45                     break;
46             }
47             if(j==num) {
48                 calcu(a,num,p,q);
49                 num++;
50             }
51             else calcu(a,j,p,q);
52             for(j=0;j<num;j++)
53             {
54                 if(strcmp(b,result[j].name)==0)
55                     break;
56             }
57             if(j==num)
58             {
59                 calcu(b,j,q,p);
60                 num++;
61             }
62             else calcu(b,j,q,p);
63         }
64         for(i=0;i<num;i++)
65         {
66             result[i].pt=result[i].w*3+result[i].d;
67             result[i].gd=result[i].wins-result[i].losts;
68         }
69         sort(result,result+num,cmp);
70         for(i=0;i<num;i++)
71         {
72             printf("%d %s %d %d %d %d %d\n",i+1,result[i].name,result[i].w,result[i].d,result[i].l,result[i].pt,result[i].gd);
73         }
74     }
75     return 0;
76 }

 

posted @ 2013-03-09 20:28  ZeroCode_1337  阅读(248)  评论(0编辑  收藏  举报