10194 - Football (aka Soccer)

strcasecmp()

一个很好用的函数,用了就ac了,呵呵#include<stdio.h>
#include<string.h>
#include<ctype.h>
struct _team
{
 char name[200];
 int earn;
 int score;
 int against;
 int difference;
 int win;
 int lose;
 int tie;
 int played;
};
struct _team team[200];
char roundname[200];
char match[200];
char _teamname1[200];
char _teamname2[200];
char name[200];
void _temp(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
void temp(int i,int j)
{
    strcpy(name,team[i].name);
    strcpy(team[i].name,team[j].name);
    strcpy(team[j].name,name);
    _temp(&team[i].earn,&team[j].earn);
    _temp(&team[i].score,&team[j].score);
    _temp(&team[i].against,&team[j].against);
    _temp(&team[i].difference,&team[j].difference);
    _temp(&team[i].win,&team[j].win);
    _temp(&team[i].lose,&team[j].lose);
    _temp(&team[i].tie,&team[j].tie);
    _temp(&team[i].played,&team[j].played);
}
int main()
{
 int i,j,k,round,n,T,a,b,cases=0;
 char *p,*_p;
    scanf("%d",&round);
 getchar();
 while(round-->0)
 {
     if(cases)
         printf("\n");
     cases++;
  gets(roundname);
  scanf("%d",&n);
  getchar();
  for(i=0;i<n;i++)
  {
   gets(team[i].name);
   team[i].score=0;
   team[i].against=0;
   team[i].win=0;
   team[i].lose=0;
   team[i].tie=0;
  }
  scanf("%d",&T);
  getchar();
  for(i=0;i<T;i++)
  {
   gets(match);
   p=match;
   _p=match;
   while(*p!='#')
    p++;
   *p='\0';
   strcpy(_teamname1,_p);
   p++;
   a=0;
   while(*p!='@')
   {
    a=a*10+*p-'0';
    p++;
   }
   p++;
   b=0;
   while(*p!='#')
   {
    b=b*10+*p-'0';
    p++;
   }
   p++;
   strcpy(_teamname2,p);
   for(j=0;j<n;j++)
    if(strcmp(_teamname1,team[j].name)==0)
       break;
   for(k=0;k<n;k++)
    if(strcmp(_teamname2,team[k].name)==0)
       break;
    if(a>b)
    {
     team[j].win++;
     team[k].lose++;
     team[j].score+=a;
     team[k].score+=b;
     team[j].against+=b;
     team[k].against+=a;
    }
    else if(a==b)
    {
        team[j].score+=a;
        team[k].score+=b;
     team[j].tie++;
     team[k].tie++;
     team[j].against+=b;
     team[k].against+=a;
    }
    else
    {
     team[k].win++;
     team[j].lose++;
     team[j].score+=a;
     team[k].score+=b;
     team[j].against+=b;
     team[k].against+=a;
    }
  }
  for(i=0;i<n;i++)
  {
   team[i].earn=3*team[i].win+team[i].tie;
   team[i].played=team[i].win+team[i].lose+team[i].tie;
   team[i].difference=team[i].score-team[i].against;
  }
  for(i=0;i<n-1;i++)
  {
      for(j=i+1;j<n;j++)
      {
          if(team[i].earn<team[j].earn)
          {temp(i,j);}
          else if(team[i].earn==team[j].earn)
          {
              if(team[i].win<team[j].win)
              {temp(i,j);}
              else if(team[i].win==team[j].win)
              {
                  if(team[i].difference<team[j].difference)
                  {temp(i,j);}
                  else if(team[i].difference==team[j].difference)
                  {
                      if(team[i].score<team[j].score)
                      {temp(i,j);}
                      else if(team[i].score==team[j].score)
                      {
                          if(team[i].played>team[j].played)
                          {temp(i,j);}
                          else if(team[i].played==team[j].played)
                          {
                              if(strcasecmp(team[i].name,team[j].name)>0)
          temp(i,j);
                          }
                          else
                          ;
                      }
                      else
                      ;
                  }
                  else
                  ;
              }
              else
              ;
          }
          else
          ;

      }
  }
  printf("%s\n",roundname);
  for(i=0;i<n;i++)
  {
      printf("%d) ",i+1);
      printf("%s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",team[i].name,team[i].earn,team[i].played,team[i].win,team[i].tie,team[i].lose,team[i].difference,team[i].score,team[i].against);
  }
 }
 return 0;
}

你可能感兴趣的:(SOC)