UVa Problem Solution: 10194 - Football (aka Soccer)


Nothing worthy to mention.

Code:
  1. /*************************************************************************
  2.  * Copyright (C) 2008 by liukaipeng                                      *
  3.  * liukaipeng at gmail dot com                                           *
  4.  *************************************************************************/
  5. /* @JUDGE_ID 00000 10194 C++ "Football (aka Soccer)" */
  6. #include <algorithm>
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <deque>
  10. #include <fstream>
  11. #include <iostream>
  12. #include <list>
  13. #include <map>
  14. #include <queue>
  15. #include <set>
  16. #include <stack>
  17. #include <string>
  18. #include <vector>
  19. using namespace std;
  20.      
  21. int const teamcount = 30;
  22. int const gamecount = 1000;
  23. int const linesize = 110;
  24. int const namesize = 31;
  25. struct standing
  26. {
  27.   standing(char *t = 0) : team(t), win(), tie(), lose(), goal(), against() {}
  28.   char *team;
  29.   int win;
  30.   int tie;
  31.   int lose;
  32.   int goal;
  33.   int against;
  34. };
  35.   
  36. struct standingcomp
  37. {
  38.   bool operator()(standing const& st1, standing const& st2)
  39.   {
  40.     int r1 = st1.win * 3 + st1.tie;
  41.     int r2 = st2.win * 3 + st2.tie;
  42.     if (r1 > r2) return true;
  43.     if (r1 < r2) return false;
  44.     r1 = st1.win;
  45.     r2 = st2.win;
  46.     if (r1 > r2) return true;
  47.     if (r1 < r2) return false;
  48.     r1 = st1.goal - st1.against;
  49.     r2 = st2.goal - st2.against;
  50.     if (r1 > r2) return true;
  51.     if (r1 < r2) return false;
  52.     r1 = st1.goal;
  53.     r2 = st2.goal;
  54.     if (r1 > r2) return true;
  55.     if (r1 < r2) return false;
  56.     r1 = st2.win + st2.tie + st2.lose;
  57.     r2 = st1.win + st1.tie + st1.lose;
  58.     if (r1 > r2) return true;
  59.     if (r1 < r2) return false;
  60.     return strcasecmp(st1.team, st2.team) < 0;
  61.   }
  62. };
  63.         
  64. struct strcomp
  65. {
  66.   bool operator()(char const *s1, char const *s2)
  67.   { return strcmp(s1, s2) < 0; }
  68. };
  69. int main(int argc, char *argv[])
  70. {
  71. #ifndef ONLINE_JUDGE
  72.   freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
  73.   freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
  74. #endif
  75.   int ncases;
  76.   scanf("%d/n", &ncases);
  77.   while (ncases-- > 0) {
  78.     char tourname[linesize];
  79.     gets(tourname);
  80.     int nteams;
  81.     scanf("%d/n", &nteams);
  82.     char teams[teamcount][namesize];
  83.     map<char *, standing, strcomp> teamstandings;
  84.     for (int i = 0; i < nteams; ++i) {
  85.       gets(teams[i]);
  86.       teamstandings.insert(make_pair(teams[i], standing(teams[i])));
  87.     }
  88.     int ngames;
  89.     scanf("%d/n", &ngames);
  90.     char line[linesize];
  91.     for (int i = 0; i < ngames; ++i) {
  92.       gets(line);
  93.       char team1[namesize];
  94.       char team2[namesize];
  95.       int goal1;
  96.       int goal2;
  97.       sscanf(line, "%[^#]#%d@%d#%[^#]", team1, &goal1, &goal2, team2);
  98.       standing& st1 = teamstandings[team1];
  99.       standing& st2 = teamstandings[team2];
  100.       st1.goal += goal1;
  101.       st1.against += goal2;
  102.       st2.goal += goal2;
  103.       st2.against += goal1;
  104.       if (goal1 > goal2) st1.win += 1, st2.lose += 1;
  105.       else if (goal1 < goal2) st1.lose += 1, st2.win += 1;
  106.       else st1.tie += 1, st2.tie += 1;
  107.     }
  108.     vector<standing> standings;
  109.     standings.reserve(nteams);
  110.     for (map<char *, standing, strcomp>::iterator it = teamstandings.begin(); 
  111.          it != teamstandings.end(); ++it)
  112.       standings.push_back(it->second);
  113.     sort(standings.begin(), standings.end(), standingcomp());
  114.     
  115.     puts(tourname);
  116.     for (int i = 0; i < nteams; ++i)
  117.       printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)/n",
  118.              i + 1, standings[i].team, standings[i].win * 3 + standings[i].tie,
  119.              standings[i].win + standings[i].tie + standings[i].lose,
  120.              standings[i].win, standings[i].tie, standings[i].lose,
  121.              standings[i].goal - standings[i].against, standings[i].goal, 
  122.              standings[i].against);
  123.     if (ncases > 0) puts("");
  124.   }
  125.   return 0;
  126. }

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值