HDU1225(字符串+简单排序 )

来源:互联网 发布:mac重装系统找不到硬盘 编辑:程序博客网 时间:2024/04/28 16:41

Football Score

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2173    Accepted Submission(s): 614


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
3Manchester VS Portsmouth 3:0Liverpool VS Manchester 1:1Liverpool VS Portsmouth 0:0Portsmouth VS Manchester 1:1Manchester VS Liverpool 2:1Liverpool VS Portsmouth 1:2
 

Sample Output
Manchester 8Portsmouth 5Liverpool 2
Hint
Hint
Huge input, scanf is recommended.
 

Author
Gao Bo
 
字符串+简单排序#include<iostream>#include<algorithm>#include<string>#include<vector>#include<map>#define MAX 100using namespace std;struct node{ string name; int score; int net_goal; int kicked_ball;}team[MAX];bool cmp(node a,node b){ if(a.score>b.score)  return true; else if(a.score<b.score)  return false; else if(a.score==b.score) {  if(a.net_goal>b.net_goal)   return true;  else if(a.net_goal<b.net_goal)   return false;  else if(a.net_goal==b.net_goal)  {   if(a.kicked_ball>b.kicked_ball)    return true;   else if(a.kicked_ball<b.kicked_ball)    return false;   else if(a.kicked_ball==b.kicked_ball)   {    return a.name<b.name;   }  } }}int main(){ string ch1,name1,name2; char ch2; int n,i,get,lost,j,k; bool flag1,flag2; while(cin>>n) {      for(i=1;i<=n;i++)   {    team[i].score=0;    team[i].net_goal=0;       team[i].kicked_ball=0;   }  j=1;  for(i=1;i<=n*(n-1);i++)  {   flag1=false;   flag2=false;   cin>>name1>>ch1>>name2>>get>>ch2>>lost;   for(k=1;k<j;k++)   {    if(team[k].name==name1)    {     flag1=true;     if(get>lost)team[k].score+=3;     else if(get==lost)team[k].score+=1;     team[k].net_goal+=(get-lost);     team[k].kicked_ball+=get;    }    if(team[k].name==name2)    {     flag2=true;     if(get<lost)team[k].score+=3;     else if(get==lost)team[k].score+=1;     team[k].net_goal+=(lost-get);     team[k].kicked_ball+=lost;    }   }      if(!flag1)   {    team[j].name=name1;    if(get>lost)team[j].score+=3;    else if(get==lost)team[j].score+=1;    team[j].net_goal+=(get-lost);    team[j].kicked_ball+=get;    j++;   }      if(!flag2)   {    team[j].name=name2;    if(get<lost)team[j].score+=3;    else if(get==lost)team[j].score+=1;    team[j].net_goal+=(lost-get);    team[j].kicked_ball+=lost;    j++;   }  }  sort(team+1,team+1+n,cmp);  for(i=1;i<j;i++)   cout<<team[i].name<<" "<<team[i].score<<endl;  cout<<endl; } return 0;}


 

原创粉丝点击