HDU 1225(简单题)
2010-08-06 14:44
330 查看
Football Score
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 942 Accepted Submission(s): 287
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 HintHint Huge input, scanf is recommended.#include <iostream> #include <vector> #include <algorithm> using namespace std; #define N 1000 struct team { char name[35]; int point; int net_g; int all_g; }node ; int len; bool cmp(team a,team b) { if(a.point != b.point) return a.point>b.point; else { if(a.net_g != b.net_g) return a.net_g>b.net_g; else { if(a.all_g != b.all_g) return a.all_g>b.all_g; else { if(strcmp(a.name,b.name)<0) return true; else return false; } } } } int main() { int n,m,i,a,b; char ch[10],t1[100],t2[100]; while (scanf("%d",&n)!=EOF) { for(i=0;i<N;i++) { strcpy(node[i].name,""); node[i].point=0; node[i].net_g=0; node[i].all_g=0; } len=0; m=n*(n-1); while (m--) { scanf("%s",t1); scanf("%s",ch); scanf("%s",t2); scanf("%d:%d",&a,&b); if(len == 0) { strcpy(node[len].name,t1); strcpy(node[len+1].name,t2); if(a>b) { node[len].point+=3; node[len+1].point+=0; } else if(a==b) { node[len].point+=1; node[len+1].point+=1; } else { node[len].point+=0; node[len+1].point+=3; } node[len].net_g+=a-b; node[len+1].net_g+=b-a; node[len].all_g+=a; node[len+1].all_g+=b; len+=2; } else { int flag1=0,flag2=0; for(i=0;i<len;i++) { if(strcmp(node[i].name,t1)==0) { if(a>b) node[i].point+=3; else if(a==b) node[i].point+=1; else node[i].point+=0; node[i].net_g+=a-b; node[i].all_g+=a; flag1=1; } else if(strcmp(node[i].name,t2)==0) { if(b>a) node[i].point+=3; else if(a==b) node[i].point+=1; else node[i].point+=0; node[i].net_g+=b-a; node[i].all_g+=b; flag2=1; } } if(flag1==0) { strcpy(node[len].name,t1); if(a>b) node[len].point+=3; else if(a==b) node[len].point+=1; else node[len].point+=0; node[len].net_g+=a-b; node[len].all_g+=a; len++; } if(flag2==0) { strcpy(node[len].name,t2); if(b>a) node[len].point+=3; else if(a==b) node[len].point+=1; else node[len].point+=0; node[len].net_g+=b-a; node[len].all_g+=b; len++; } } } sort(node,node+len,cmp); for(i=0;i<len;i++) { printf("%s %d/n",node[i].name,node[i].point); } printf("/n"); } return 0; }
相关文章推荐
- HDU 5373 The shortest problem (简单模拟)
- hdu 1241 简单的搜索
- hdu 1225 Football Score
- HDU 4720 Naive and Silly Muggles (简单计算几何)
- hdu 1754 简单的线段树应用
- HDOJ(HDU) 1976 Software Version(简单判断)
- 简单的01背包 HDU - 2602 1864 二维、一维数组
- hdu 1011 简单树形背包。
- hdu 4730 We Love MOE Girls【简单字符串】
- HDU 3706 Second My Problem First 单调队列简单题
- HDU - 1372 Knight Moves ( 简单BFS + floodfill )
- HDU 4985 Little Pony and Permutation(简单模拟)
- hdu 1846 (简单博弈题)
- HDU1533-Going Home 简单KM
- HDU 5585 Numbers(字符串的处理 简单题)——BestCoder Round #64(div.2)
- [BestCoder Round #3] hdu 4907 Task schedule (模拟简单题)
- HDU 2191 简单01背包
- HDU 4508湫湫系列故事――减肥记i-简单的完全背包
- HDU 1049 Climbing Worm(简单的规律题)
- hdu 1788 Chinese remainder theorem again((数学:简单题)