UVA10194 Football (aka Soccer)

做题晕了,两处笔误没看见,还漏了一个排序条件,真不爽。

对了,按字典排序不区分大小写,题目又没说明白。

题目:

Football (aka Soccer)

 

 Problem A: Football (aka Soccer) 

 

The Problem

Football the most popular sport in the world (americans insist to call it "Soccer", but we will call it "Football"). As everyone knows, Brasil is the country that have most World Cup titles (four of them: 1958, 1962, 1970 and 1994). As our national tournament have many teams (and even regional tournaments have many teams also) it's a very hard task to keep track of standings with so many teams and games played!

So, your task is quite simple: write a program that receives the tournament name, team names and games played and outputs the tournament standings so far.

A team wins a game if it scores more goals than its oponent. Obviously, a team loses a game if it scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3 points for each win, 1 point for each tie and 0 point for each loss.

Teams are ranked according to these rules (in this order):

 

  1. Most points earned.
  2. Most wins.
  3. Most goal difference (i.e. goals scored - goals against)
  4. Most goals scored.
  5. Less games played.
  6. Lexicographic order.

The Input

The first line of input will be an integer N in a line alone (0 < N < 1000). Then, will follow N tournament descriptions. Each one begins with the tournament name, on a single line. Tournament names can have any letter, digits, spaces etc. Tournament names will have length of at most 100. Then, in the next line, there will be a number T (1 < T <= 30), which stands for the number of teams participating on this tournament. Then will follow T lines, each one containing one team name. Team names may have any character that have ASCII code greater than or equal to 32 (space), except for '#' and '@' characters, which will never appear in team names. No team name will have more than 30 characters.

Following to team names, there will be a non-negative integer G on a single line which stands for the number of games already played on this tournament. G will be no greater than 1000. Then, G lines will follow with the results of games played. They will follow this format:

team_name_1#goals1@goals2#team_name_2

For instance, the following line:

Team A#3@1#Team B

Means that in a game between Team A and Team B, Team A scored 3 goals and Team B scored 1. All goals will be non-negative integers less than 20. You may assume that there will not be inexistent team names (i.e. all team names that appear on game results will have apperead on the team names section) and that no team will play against itself.

The Output

For each tournament, you must output the tournament name in a single line. In the next T lines you must output the standings, according to the rules above. Notice that should the tie-breaker be the lexographic order, it must be done case insenstive. The output format for each line is shown bellow:

[a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])

Where:

  • [a] = team rank
  • [b] = total points earned
  • [c] = games played
  • [d] = wins
  • [e] = ties
  • [f] = losses
  • [g] = goal difference
  • [h] = goals scored
  • [i] = goals against

There must be a single blank space between fields and a single blank line between output sets. See the sample output for examples.

Sample Input

 

2
World Cup 1998 - Group A
4
Brazil
Norway
Morocco
Scotland
6
Brazil#2@1#Scotland
Norway#2@2#Morocco
Scotland#1@1#Norway
Brazil#3@0#Morocco
Morocco#3@0#Scotland
Brazil#1@2#Norway
Some strange tournament
5
Team A
Team B
Team C
Team D
Team E
5
Team A#1@1#Team B
Team A#2@2#Team C
Team A#0@0#Team D
Team E#2@1#Team C
Team E#1@2#Team D

Sample Output

 

World Cup 1998 - Group A
1) Brazil 6p, 3g (2-0-1), 3gd (6-3)
2) Norway 5p, 3g (1-2-0), 1gd (5-4) 
3) Morocco 4p, 3g (1-1-1), 0gd (5-5)
4) Scotland 1p, 3g (0-1-2), -4gd (2-6)

Some strange tournament
1) Team D 4p, 2g (1-1-0), 1gd (2-1)
2) Team E 3p, 2g (1-0-1), 0gd (3-3)
3) Team A 3p, 3g (0-3-0), 0gd (3-3)
4) Team B 1p, 1g (0-1-0), 0gd (1-1)
5) Team C 1p, 2g (0-1-1), -1gd (3-4)

© 2001 Universidade do Brasil (UFRJ). Internal Contest 2001.

解答:

 

  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4 #include<ctype.h>
  5 struct team
  6 {
  7     char name[35];
  8     int pnt;
  9     int play;
 10     int win;
 11     int tie;
 12     int loss;
 13     int gd;
 14     int gs;
 15     int ga;
 16 };
 17 int cmp_team(const void *a,const void *b)
 18 {
 19     team *_a=(team*)a;
 20     team *_b=(team*)b;
 21     if(_a->pnt!=_b->pnt)
 22     {
 23         return _b->pnt-_a->pnt;
 24     }
 25     else if(_a->win!=_b->win)
 26     {
 27         return _b->win-_a->win;
 28     }
 29     else if(_a->gd!=_b->gd)
 30     {
 31         return _b->gd-_a->gd;
 32     }
 33     else if(_a->gs!=_b->gs)
 34     {
 35         return _b->gs-_a->gs;
 36     }
 37     else if(_a->play!=_b->play)
 38     {
 39         return _a->play-_b->play;
 40     }
 41     else
 42     {
 43         int i;
 44         char s1[100],s2[100];
 45         for(i=0;i<strlen(_a->name);i++)
 46             s1[i]=tolower(_a->name[i]);
 47         s1[i]='\0';
 48         for(i=0;i<strlen(_b->name);i++)
 49             s2[i]=tolower(_b->name[i]);
 50         s2[i]='\0';
 51         return strcmp(s1,s2);
 52     }
 53 }
 54 team tt[100];
 55 int t,g;
 56 char gname[110],cpt[100];
 57 void clean(team *t)
 58 {
 59     memset(t->name,0,sizeof(t->name));
 60     t->pnt=0;
 61     t->play=0;
 62     t->win=0;
 63     t->tie=0;
 64     t->loss=0;
 65     t->gd=0;
 66     t->gs=0;
 67     t->ga=0;
 68 }
 69 void change(char *g)
 70 {
 71     int i,j,k,p=0,fir,sec,mid,flag=0,n1=0;
 72     char tmp[50];
 73     for(i=0;i<strlen(g);i++)
 74     {
 75         if(g[i]=='#'&&isdigit(g[i+1]))
 76         {
 77             tmp[p]='\0';
 78             for(j=0;j<t;j++)
 79             {
 80                 if(strcmp(tmp,tt[j].name)==0)
 81                 {
 82                     fir=j;
 83                     for(k=i+1;g[k]!='@';k++)
 84                     {
 85                         if(isdigit(g[k]))
 86                             n1=10*n1+g[k]-'0';
 87                     }
 88                     tt[j].gs+=n1;
 89                     mid=k;
 90                     flag=1;
 91                     break;
 92                 }
 93             }
 94 
 95         }
 96         if(flag==1)
 97             break;
 98         tmp[p]=g[i];
 99         p++;
100     }
101     int n2=0;
102     flag=0,p=0;
103     for(i=mid+1;g[i]!='#';i++)
104     {
105         if(isdigit(g[i]))
106             n2=10*n2+g[i]-'0';
107     }
108     for(j=i+1;j<strlen(g);j++)
109     {
110         tmp[p]=g[j];
111         p++;
112     }
113     tmp[p]='\0';
114     for(i=0;i<t;i++)
115     {
116         if(strcmp(tmp,tt[i].name)==0)
117         {
118             sec=i;
119             tt[i].gs+=n2;
120             break;
121         }
122     }
123     tt[fir].play++;
124     tt[sec].play++;
125     tt[fir].ga+=n2;
126     tt[sec].ga+=n1;
127     tt[fir].gd+=(n1-n2);
128     tt[sec].gd+=(n2-n1);
129     if(n1>n2)
130     {
131         tt[fir].win++;
132         tt[sec].loss++;
133         tt[fir].pnt+=3;
134     }
135     else if(n1<n2)
136     {
137         tt[fir].loss++;
138         tt[sec].win++;
139         tt[sec].pnt+=3;
140     }
141     else
142     {
143         tt[fir].tie++;
144         tt[sec].tie++;
145         tt[fir].pnt++;
146         tt[sec].pnt++;
147     }
148 
149 }
150 int main()
151 {
152     int n;
153     scanf("%d",&n);
154     getchar();
155     while(n--)
156     {
157         int i,j;//t team_num;g game_num
158         gets(gname);
159         scanf("%d",&t);
160         getchar();
161         for(i=0;i<t;i++)
162             clean(&tt[i]);
163         for(i=0;i<t;i++)
164             gets(tt[i].name);
165         scanf("%d",&g);
166         getchar();
167         for(i=0;i<g;i++)
168         {
169             gets(cpt);
170             change(cpt);
171         }
172         qsort(tt,t,sizeof(team),cmp_team);
173         puts(gname);
174         for(i=0;i<t;i++)
175         {
176             printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,tt[i].name,tt[i].pnt,tt[i].play,tt[i].win,tt[i].tie,tt[i].loss,tt[i].gd,tt[i].gs,tt[i].ga);
177         }
178         if(n>0)
179             printf("\n");
180     }
181 }

 

 

 

posted @ 2013-02-19 21:49  上白泽慧音  阅读(485)  评论(0编辑  收藏  举报