Football Score
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3124 Accepted Submission(s): 890
Problem Description
Football is one of the greatest games in the world. Lots of people like to play football. After one season of matches, the header has to calculate the last scores of every team. He is too lazy that he doesn't want to calculate, so he asks you to write a program for him to solve the problem.
Here are the rules:
1 Every team has to match with all the other teams.
2 Every two teams have to match for two times,one at home and one away.
3 In one match, the winner will get 3 points, the loser will get 0 point. If it is draw, both of them will get 1 point.
Input
The input consists of many test cases. In each case, there will be a number N in the first line which means the number of teams. Followed by N * (N – 1)lines. Each line stands for a match between two teams. The format is: "Team1 VS Team2 p:q", p stands for the balls that Team1 has kicked in and q stands for the balls that Team2 has kicked in. p and q are not greater than 9.
Process to the end of file.
Output
For each test case, output the teams and their scores in descending order. One line a team, the format is: "TeamX scores". If two teams get the same score, the one with high net goals will be ahead, which net goal means the difference between the total balls that the team kicked in and the total balls that the team lost. IE: if one team kicked in 30 balls and lost 40 balls, then the net goal is 30 – 40 = -10. If two teams have the same score and the same net goal, the one whose kicked in balls is bigger will be ahead. If two teams have the same score and the same net goal and the same kicked in balls, they will be outputed in alphabetic order.
Output a blank line after each test case.
Sample Input
3
Manchester VS Portsmouth 3:0
Liverpool VS Manchester 1:1
Liverpool VS Portsmouth 0:0
Portsmouth VS Manchester 1:1
Manchester VS Liverpool 2:1
Liverpool VS Portsmouth 1:2
Sample Output
Manchester 8
Portsmouth 5
Liverpool 2
Huge input, scanf is recommended.
Author
Gao Bo
Source
杭州电子科技大学第三届程序设计大赛
Recommend
Ignatius.L | We have carefully selected several similar problems for you: 1221 1224 1220 1226 1230
排序先后顺序为1.得分。2.净胜球,即赢球减输球。3. 进球。4.队名字母排序,按ASCII码排。 输出队名和得分。 若赢得3分,平局1分,输0分。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t;
struct node{
int s1,s2,s3;//得分,净胜球,进球
char name[50];
}no[50000];
int find(char str[]){//查找字符串并返回下标
int i;
if(t==-1){
strcpy(no[0].name,str);
t=0;
return t;
}//第一个字符串存档
for(i=0;i<=t;i++)
if(strcmp(no[i].name,str)==0)
return i;
t++;
strcpy(no[t].name,str);
return t;
}
int cmp(const void *a,const void *b){
if((*(struct node*)a).s1!=(*(struct node*)b).s1)
return (*(struct node*)b).s1-(*(struct node*)a).s1;
if((*(struct node*)a).s2!=(*(struct node*)b).s2)
return (*(struct node*)b).s2-(*(struct node*)a).s2;
if((*(struct node*)a).s3!=(*(struct node*)b).s3)
return (*(struct node*)b).s3-(*(struct node*)a).s3;
return strcmp((*(struct node*)a).name,(*(struct node*)b).name);
}
int main(){
int n,k,i,x,y,a,b;
char str1[50],str2[10],str3[50];
while(~scanf("%d",&n)){
t=-1;
k=n*(n-1);
memset(no,0,sizeof(no));
while(k--){
scanf("%s%s%s %d:%d",str1,str2,str3,&a,&b);
x=find(str1);
y=find(str3);
if(a>b) no[x].s1+=3;//得分
else if(a==b){
no[x].s1+=1;
no[y].s1+=1;
}
else no[y].s1+=3;
no[x].s2+=(a-b); no[x].s3+=a;//净胜球,进球
no[y].s2+=(b-a); no[y].s3+=b;
}
qsort(no,n,sizeof(no[0]),cmp);//
for(i=0;i<n;i++)
printf("%s %d\n",no[i].name,no[i].s1);
printf("\n");
}
return 0;
}