杭电1225 Football Score (结构体排序)

Football Score

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


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
Hint
Hint
Huge input, scanf is recommended.

 

/*

#include<stdio.h>
#include<string.h>
#include<algorithm>
using std::sort;
#define maxn 10000
#define MAN 100
struct foot{
       int score;
       int net;
       int kickin;
       int lost;
       char name[50];
       };
 struct foot s[maxn]; 
 /*
  int find(char str[], int k){
 for(int i = 0; i < k; ++i)
  if(!strcmp(str, s[i].name)) return i;
 return -1;
}
  */        
int find(char name0[] ,int k)
{
     int j;
   for(j=0;j<k;j++)
     if(strcmp(s[j].name,name0)==0)return j;
   return -1;
}

bool cmp(foot a,foot b)
{
   if(a.score>b.score) return 1;
      if(a.score==b.score&&a.net>b.net) return 1;
        if(a.score==b.score&&a.net==b.net && a.kickin>b.kickin) return 1;
             if(a.score==b.score &&  a.net==b.net &&  a.kickin==b.kickin && strcmp(a.name,b.name)<0 ) return 1;
        return 0;
}

int main()
{
    int N,n;
    int i,a,b;
    int kickin1,lost1;
    char name1[MAN], name2[MAN];
    while(scanf("%d",&n)!=EOF)
    {
        int num=0;
        memset(s,0,sizeof(s));
       for( i=0;i<n*(n-1);i++)
{
        scanf("%s VS %s %d:%d",name1,name2,&kickin1,&lost1 );
          // int sign=kickin1-lost1;
           if(kickin1>lost1){a=3;b=0;}
             else if(kickin1==lost1){a=1;b=1;}
               else{a=0;b=3;}
           int x=find(name1,num);
          // printf("x= %d \n",x);
        if(x!=-1)
          { 
           s[x].kickin+=kickin1;
           s[x].lost+=lost1;
           s[x].score+=a;
         //  printf(" %dth score%d\n",x,s[x].score);
         //  s[x].net+=sign;
          }
        else
         {
           strcpy(s[num].name,name1);
            s[num].kickin+=kickin1;
            s[num].lost+=lost1;
            s[num].score+=a;
       //    printf("%dth score %d\n",num,s[num].score);
           // s[num].net+=sign;
            num++;
         }
         int y=find(name2,num);
        // printf("y= %d \n",y);
        if(y!=-1)
          { 
           s[y].kickin+=lost1;
           s[y].lost+=kickin1;
           s[y].score+=b;
        //   printf(" %dth score%d\n",y,s[y].score);
          // s[y].net-=sign;
          }
        else
         {
           strcpy(s[num].name,name2);
            s[num].kickin+=lost1;
            s[num].lost+=kickin1;
            s[num].score+=b;
        //    printf(" %dth score %d\n",num,s[num].score);
          //  s[num].net-=sign;
            num++;
         }
     
}

   for(int i=0;i<n;i++)
     s[i].net=s[i].kickin-s[i].lost;
sort(s,s+n,cmp);

   for(int i=0;i<n;i++)
     printf("%s %d\n",s[i].name,s[i].score);
     printf("\n");
    }
return 0;
}

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值