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):
- Most points earned.
- Most wins.
- Most goal difference (i.e. goals scored - goals against)
- Most goals scored.
- Less games played.
- 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_2For instance, the following line:
Team A#3@1#Team BMeans 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
- [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.
这题的思路很好想,但是确实从昨天下午,一直到今天,要注意的是对字符串进行排序的时候,忽略大小写,我已开始想用strlwr函数想统一编程小写,但我发现这样无法通过编译,就自己写了一个都编程小写的函数,然后在进行比较。
#include <stdio.h>
#include <string.h>
int b[2000],c[2000][4],g[2000][3];
char s1[2000][100],s2[1000],s3[100],s4[100],s5[100];
char s6[100],s7[100];
int main()
{
int i,j,n,m,s,t,l,score1,score2,x,k;
int flag1,flag2;
int l1,l2;
scanf("%d",&m);
getchar();
while(m--)
{
gets(s5);
scanf("%d",&n);
getchar();
for(i=0;i<=n-1;i++)
{
b[i]=0;
c[i][0]=c[i][1]=c[i][2]=c[i][3]=0;
g[i][0]=g[i][1]=g[i][2]=0;
gets(s1[i]);
}
scanf("%d",&t);
getchar();
for(i=0;i<=t-1;i++)
{
gets(s2);
s=0;
l=strlen(s2);
flag1=0;
for(j=0;j<=l-1;j++)
{
if(s2[j]!='#')
{
s3[flag1]=s2[j];
flag1+=1;
}else
{
s3[flag1]='\0';
break;
}
}
x=j+1;
for(j=0;j<=n-1;j++)
{
if(strcmp(s3,s1[j])==0)
{
flag1=j;
break;
}
}
for(j=x;j<=l-1;j++)
{
if(s2[j]!='@'&&s2[j]!='#')
{
s=s*10+s2[j]-'0';
}else if(s2[j]=='@')
{
score1=s;
s=0;
}else if(s2[j]=='#')
{
score2=s;
s=0;
break;
}
}
flag2=0;
for(j=j+1;j<=l-1;j++)
{
s3[flag2]=s2[j];
flag2+=1;
}
s3[flag2]='\0';
for(j=0;j<=n-1;j++)
{
if(strcmp(s1[j],s3)==0)
{
flag2=j;
break;
}
}
if(score1>score2)
{
b[flag1]+=3;
c[flag1][0]+=1;
c[flag2][2]+=1;
}else if(score1==score2)
{
b[flag1]+=1;
b[flag2]+=1;
c[flag1][1]+=1;
c[flag2][1]+=1;
}else
{
b[flag2]+=3;
c[flag2][0]+=1;
c[flag1][2]+=1;
}
c[flag1][3]=c[flag1][0]+c[flag1][1]+c[flag1][2];
c[flag2][3]=c[flag2][0]+c[flag2][1]+c[flag2][2];
g[flag1][0]+=score1; g[flag1][1]+=score2;
g[flag2][0]+=score2; g[flag2][1]+=score1;
g[flag1][2]=g[flag1][0]-g[flag1][1];
g[flag2][2]=g[flag2][0]-g[flag2][1];
}
for(i=0;i<=n-2;i++)
{
k=i;
for(j=i+1;j<=n-1;j++)
{
if(b[j]>b[k])
{
k=j;
}else if(b[j]==b[k])
{
if(c[j][0]>c[k][0])
{
k=j;
}else if(c[j][0]==c[k][0])
{
if(g[j][2]>g[k][2])
{
k=j;
}else if(g[j][2]==g[k][2])
{
if(g[j][0]>g[k][0])
{
k=j;
}else if(g[j][0]==g[k][0])
{
if(c[j][3]<c[k][3])
{
k=j;
}else if(c[j][3]==c[k][3])
{
strcpy(s6,s1[j]);
strcpy(s7,s1[k]);
l1=strlen(s6);
for(x=0;x<=l1-1;x++)
{
if(s6[x]>='A'&&s6[x]<='Z')
{
s6[x]+=32;
}
}
l1=strlen(s7);
for(x=0;x<=l1-1;x++)
{
if(s7[x]>='A'&&s7[x]<='Z')
{
s7[x]+=32;
}
}
if(strcmp(s6,s7)<0)
{
k=j;
}
}
}
}
}
}
}
if(k!=i)
{
t=b[k];b[k]=b[i];b[i]=t;
for(x=0;x<=3;x++)
{
t=c[k][x];c[k][x]=c[i][x];c[i][x]=t;
}
for(x=0;x<=2;x++)
{
t=g[k][x];g[k][x]=g[i][x];g[i][x]=t;
}
strcpy(s4,s1[k]);
strcpy(s1[k],s1[i]);
strcpy(s1[i],s4);
}
}
puts(s5);
for(i=0;i<=n-1;i++)
{
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,s1[i],b[i],c[i][3],c[i][0],c[i][1],c[i][2],g[i][2],g[i][0],g[i][1]);
}
if(m)
{
printf("\n");
}
}
return 0;
}