2013
12-04

Football Score

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.

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.

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.

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

Manchester 8
Portsmouth 5
Liverpool 2

HintHint
Huge input, scanf is recommended.

HDU-1225-Football Score

http://acm.hdu.edu.cn/showproblem.php?pid=1225

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,t;
struct cam
{
char str[50]; //队名
int score1; //得分
int score2; //净胜球
int score3; //进球
}list[50000];
int find(char ss[])  //查找字符串并返回下标
{
int i;
if(t==-1)
{
strcpy(list[0].str,ss);
t=0;
return t;
}
for(i=0;i<=t;i++)
if(strcmp(list[i].str,ss)==0)
return i;
t++;
strcpy(list[t].str,ss);
return t;
}
int cmp(const void *a,const void *b)  //从大到小排序
{
if((*(struct cam *)a).score1!=(*(struct cam *)b).score1)
return (*(struct cam *)b).score1-(*(struct cam *)a).score1;
if((*(struct cam *)a).score2!=(*(struct cam *)b).score2)
return (*(struct cam *)b).score2-(*(struct cam *)a).score2;
if((*(struct cam *)a).score3!=(*(struct cam *)b).score3)
return (*(struct cam *)b).score3-(*(struct cam *)a).score3;
return strcmp((*(struct cam *)a).str,(*(struct cam *)b).str);
}
int main()
{
int i,k;
char s1[50],s2[50],temp[10];
int a,b;
int p,q;
while(scanf("%d",&n)!=EOF)
{
k=n*(n-1);
t=-1;
memset(list,0,sizeof(list));
while(k--)
{
scanf("%s%s%s %d:%d",s1,temp,s2,&a,&b);
p=find(s1);
q=find(s2);
if(a>b)    //得分
list[p].score1+=3;
else if(a==b)
{
list[p].score1+=1;
list[q].score1+=1;
}
else
list[q].score1+=3;
list[p].score2+=(a-b);  //净胜球
list[q].score2+=(b-a);
list[p].score3+=a;  //进球
list[q].score3+=b;
}
qsort(list,n,sizeof(struct cam),cmp);
for(i=0;i<n;i++)
printf("%s %d\n",list[i].str,list[i].score1);
printf("\n");
}
return 0;
}

1. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！

2. 第一题是不是可以这样想，生了n孩子的家庭等价于n个家庭各生了一个1个孩子，这样最后男女的比例还是1:1