因为痛,所以叫青春

我有一个梦想:穷屌丝变身富屌丝
uva10194 - Football (aka Soccer)
我都有些想要放弃这道题的想法了,突然间我找到了一本书上有这道题目的翻译,虽然没有题解,但是让我知道了题目的意思就行了,经过一个半小时的奋战,中间 错了好就次,不是因为算法,而是因为粗心写错了一个变量,导致我一直做不出结果,后来又因为那个字符串比较函数,在不同的编译器上是要调用的不同的库函数 的,因为刚开始不知道这个,所以CE了几次,下面是代码
View Code
1 #include<stdio.h>
  2 #include<stdlib.h>
  3 #include<string.h>
  4 struct data
  5 {
  6     char a[35];
  7     int b, c, d, e, f, g, h, i;
  8 }team[31];
  9 int cmp(const void *x,const void *y)
 10 {
 11     if(((struct data *)x)->b != ((struct data *)y)->b)
 12         return (((struct data *)x)->b > ((struct data *)y)->b?-1:1);
 13     else if(((struct data *)x)->d != ((struct data *)y)->d)
 14         return (((struct data *)x)->d > ((struct data *)y)->d?-1:1);
 15     else if(((struct data *)x)->g != ((struct data *)y)->g)
 16         return (((struct data *)x)->g > ((struct data *)y)->g?-1:1);
 17     else if(((struct data *)x)->h != ((struct data *)y)->h)
 18         return (((struct data *)x)->h > ((struct data *)y)->h?-1:1);
 19     else if(((struct data *)x)->c != ((struct data *)y)->c)
 20         return (((struct data *)x)->c > ((struct data *)y)->c?1:-1);
 21     return strcasecmp(((struct data *)x)->a,((struct data *)y)->a)<0?-1:1;
 22     //这里的strcasecmp函数,在VC++6.0上面是不支持调用的最后用code blocks
 23 }
 24 int main()
 25 {
 26     int Time;
 27     scanf("%d",&Time);
 28     getchar();
 29     while(Time--)
 30     {
 31         char game[101];
 32         gets(game);
 33         int T, i, N;
 34         scanf("%d",&T);
 35         getchar();
 36         for(i = 0;i < T; i++)
 37         {
 38             gets(team[i].a);
 39             team[i].b = 0;
 40             team[i].c = 0;
 41             team[i].d = 0;
 42             team[i].e = 0;
 43             team[i].f = 0;
 44             team[i].g = 0;
 45             team[i].h = 0;
 46             team[i].i = 0;
 47         }
 48         scanf("%d",&N);
 49         getchar();
 50         char ch, st[35];
 51         for(i = 0;i < N; i++)
 52         {
 53             int k1, k2, r = 0, j = 0;
 54             while((ch = getchar()))
 55             {
 56                 if(ch == '#')break;
 57                 else
 58                     st[j++] = ch;
 59             }
 60             st[j] = '\0';
 61             scanf("%d",&k1);
 62             for(j = 0;j < T; j++)
 63             {
 64                 if(strcmp(team[j].a,st) == 0)
 65                 {
 66                     team[j].c++;
 67                     break;
 68                 }
 69             }
 70             getchar();
 71             scanf("%d",&k2);
 72             getchar();
 73             gets(st);
 74             for(r = 0;r < T; r++)
 75             {
 76                 if(strcmp(team[r].a,st) == 0)
 77                 {
 78                     team[r].c++;
 79                     break;
 80                 }
 81             }
 82             team[r].i += k1;
 83             team[j].i += k2;
 84             team[r].h += k2;
 85             team[j].h += k1;
 86             if(k1 > k2)
 87             {
 88                 team[r].f++;
 89                 team[j].b += 3;
 90                 team[j].d++;
 91             }
 92             else if(k2 > k1)
 93             {
 94                 team[j].f++;
 95                 team[r].b += 3;
 96                 team[r].d++;
 97             }
 98             else
 99             {
100                 team[r].e++;
101                 team[j].e++;
102                 team[r].b++;
103                 team[j].b++;
104             }
105         }
106         int j;
107         for(j = 0;j < T; j++)
108             team[j].g = team[j].h - team[j].i;
109         qsort(team,T,sizeof(team[0]),cmp);
110         puts(game);
111         for(j = 0;j < T; j++)
112             printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",j+1,team[j].a,team[j].b,team[j].c,team[j].d,team[j].e,team[j].f,team[j].g,team[j].h,team[j].i);
113         if(Time)
114             printf("\n");
115     }
116     return 0;
117 }

posted on 2012-07-20 21:47  Nice!  阅读(518)  评论(2编辑  收藏  举报