• UVa 10194


      题目大意:给若干个球队和比赛结果,按照给定的规则给球队排名。

      多关键字域排序,题目不难,只是太繁琐,注意在按名字排名时是大小写不敏感的,在这里WA了一次...

      1 #include <cstdio>
      2 #include <cctype>
      3 #include <cstring>
      4 #include <algorithm>
      5 using namespace std;
      6 
      7 struct Team
      8 {
      9     char name[35], tname[35];
     10     int point, game, win, tie, loss, diff, scored, against;
     11     bool operator < (const Team& t) const
     12     {
     13         if (point != t.point)  return point > t.point;
     14         if (win != t.win)  return win > t.win;
     15         if (diff != t.diff)  return diff > t.diff;
     16         if (scored != t.scored)  return scored > t.scored;
     17         if (game != t.game)  return game < t.game;
     18         return strcmp(tname, t.tname) < 0;
     19     }
     20         
     21 };
     22 Team team[35];
     23 
     24 int main()
     25 {
     26 #ifdef LOCAL
     27     freopen("in", "r", stdin);
     28 #endif
     29     char tourn[110];
     30     int T;
     31     scanf("%d", &T);
     32     getchar();
     33     while (T--)
     34     {
     35         memset(team, 0, sizeof(team));
     36         gets(tourn);
     37         int n;
     38         scanf("%d", &n);
     39         getchar();
     40         for (int i = 0; i < n; i++)
     41         {
     42             gets(team[i].name);
     43             for (int j = 0; j <= strlen(team[i].name); j++)
     44                 team[i].tname[j] = tolower(team[i].name[j]);
     45         }
     46         int k;
     47         scanf("%d", &k);
     48         getchar();
     49         char tmp[200];
     50         while (k--)
     51         {
     52             gets(tmp);
     53             char name1[35], name2[35];
     54             int len1 = strchr(tmp, '#') - tmp;
     55             memcpy(name1, tmp, len1);
     56             name1[len1] = 0;
     57             int a, b;
     58             sscanf(strchr(tmp, '#')+1, "%d", &a);
     59             sscanf(strchr(tmp, '@')+1, "%d", &b);
     60             int len2 = strlen(strrchr(tmp, '#')+1);
     61             memcpy(name2, strrchr(tmp, '#')+1, len2);
     62             name2[len2] = 0;
     63             int p, q;
     64             for (int i = 0; i < n; i++)
     65                 if (strcmp(team[i].name, name1) == 0)
     66                 {
     67                     p = i;
     68                     break;
     69                 }
     70             for (int i = 0; i < n; i++)
     71                 if (strcmp(team[i].name, name2) == 0)
     72                 {
     73                     q = i;
     74                     break;
     75                 }
     76             team[p].game++;
     77             team[q].game++;
     78             if (a > b)
     79             {
     80                 team[p].win++;
     81                 team[p].point += 3;
     82                 team[q].loss++;
     83             }
     84             else if (a == b)
     85             {
     86                 team[p].tie++;
     87                 team[p].point++;
     88                 team[q].tie++;
     89                 team[q].point++;
     90             }
     91             else 
     92             {
     93                 team[p].loss++;
     94                 team[q].win++;
     95                 team[q].point += 3;
     96             }
     97             team[p].diff += (a-b);
     98             team[q].diff += (b-a);
     99             team[p].scored += a;
    100             team[q].scored += b;
    101             team[p].against += b;
    102             team[q].against += a;
    103         }
    104         sort(team, team+n);
    105         printf("%s
    ", tourn);
    106         for (int i = 0; i < n; i++)
    107             printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)
    ", i+1, team[i].name, team[i].point, team[i].game, team[i].win, team[i].tie, team[i].loss, team[i].diff, team[i].scored, team[i].against);
    108         if (T)  printf("
    ");
    109     }
    110     return 0;
    111 }
    112             
    View Code
  • 相关阅读:
    《Linux C一站式学习》第七章 结构体
    《Linux C一站式学习》第三章 简单的函数
    《Windows程序设计》第一章 起步
    CSS在线课程学习笔记
    《Windows程序设计》第三章 窗口和消息
    window.open与window.showModalDialog中主页面与从页面间的通信(原创) 中庸
    php文件实现将大文件导入到mysql数据库中
    我为何爱读代码?你为何也应当爱?
    解决phpMyAdmin导入mysql数据库超过2M的问题
    对linux交换分区swap的一些认识总结
  • 原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3292500.html
Copyright © 2020-2023  润新知