http://acm.hdu.edu.cn/showproblem.php?pid=1225
一道超级简单的题,就因为我忘记写return,就wa好久,拜托我自己细心一点。
学习的地方:不过怎么查找字符串并返回下标
Football Score
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2739 Accepted Submission(s): 785
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.
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.
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.
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
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int t; struct node { char name[150]; int kick; int net; int score; }a[50000]; bool cmp(node b,node c) { if(b.score==c.score) { if(b.net==c.net) { if(b.kick==c.kick) return strcmp(b.name,c.name)<0?1:0; else return b.kick>c.kick; } else return b.net>c.net; } else return b.score>c.score; } int find(char ss[]) //查找字符串并返回下标 { int i; if(t==-1) { strcpy(a[0].name,ss); t=0; return t; } for(i=0;i<=t;i++) if(strcmp(a[i].name,ss)==0) return i; t++; strcpy(a[t].name,ss); return t; } int main() { int n,i,x,y,p,q; char str1[100],str2[40],str3[100]; while(~scanf("%d",&n)) { t=-1; memset(a,0,sizeof(a)); for(i=1;i<=n*(n-1);i++) { scanf("%s",str1); x=find(str1); scanf("%s",str2); scanf("%s",str3); y=find(str3); scanf("%d:%d",&p,&q); a[x].kick+=p; a[x].net+=p-q; a[y].kick+=q; a[y].net+=q-p; if(p>q) a[x].score+=3; else if(q>p) a[y].score+=3; else { a[x].score+=1; a[y].score+=1; } } sort(a,a+t+1,cmp); for(i=0;i<=t;i++) { printf("%s %d ",a[i].name,a[i].score); } printf(" "); } return 0; }