Advertisement
Malinovsky239

Codeforces Beta Round #19.Task A

Jun 16th, 2011
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cstring>
  5. #include <map>
  6.  
  7. #define N 100
  8.  
  9. using namespace std;
  10.  
  11. struct three
  12. {
  13.     int points, scored, missed;
  14. };
  15.  
  16. struct team
  17. {
  18.     string name;
  19.     three result;
  20.  
  21.     team() {}
  22.  
  23.     team(string s, three a)
  24.     {
  25.         name = s, result = a;
  26.     }
  27. };
  28.  
  29. bool operator < (team a1, team a2)
  30. {
  31.     if (a1.result.points == a2.result.points &&
  32.         a1.result.scored - a1.result.missed == a2.result.scored - a2.result.missed)
  33.             return a1.result.scored > a2.result.scored;
  34.  
  35.     if (a1.result.points == a2.result.points)
  36.         return a1.result.scored - a1.result.missed > a2.result.scored - a2.result.missed;
  37.  
  38.     return a1.result.points > a2.result.points;        
  39. }
  40.  
  41. char team1[N], match[N];
  42. map<string, three> table;
  43. string out[N];
  44. team res[N];
  45.  
  46. int main()
  47. {
  48.     int n;
  49.     scanf("%d", &n);
  50.     for (int i = 0; i < n; i++)
  51.     {
  52.         string name;
  53.         scanf("%s", team1);
  54.         name = team1;
  55.         table[name].points = table[name].scored = table[name].missed = 0;
  56.     }
  57.  
  58.     for (int i = 0; i < (n - 1) * n / 2; i++)
  59.     {
  60.         scanf("%s", match);
  61.         string t1 = "", t2 = "";
  62.  
  63.         int len = strlen(match), j = 0;
  64.         for (j = 0; ; j++)
  65.         {
  66.             if (match[j] == '-') break;
  67.             t1 += match[j];                                
  68.         }
  69.  
  70.         j++;
  71.         for (; j < len; j++)
  72.         {
  73.             if (match[j] == '-') break;
  74.             t2 += match[j];                                
  75.         }
  76.        
  77.         int score1, score2;
  78.         scanf("%d%*c%d", &score1, &score2);
  79.  
  80.         table[t1].scored += score1;
  81.         table[t2].scored += score2;
  82.         table[t1].missed += score2;
  83.         table[t2].missed += score1;
  84.  
  85.         if (score1 == score2)
  86.             table[t1].points++, table[t2].points++;
  87.  
  88.         if (score1 > score2)
  89.             table[t1].points += 3;
  90.  
  91.         if (score1 < score2)
  92.             table[t2].points += 3;
  93.     }
  94.  
  95.     int j = 0;
  96.  
  97.     for (map<string, three>::iterator i = table.begin(); i != table.end(); i++)
  98.         res[j++] = team((*i).first, (*i).second);      
  99.  
  100.     sort(res, res + j);
  101.  
  102.     for (int i = 0; i < n/ 2; i++)
  103.         out[i] = res[i].name;
  104.  
  105.     sort(out, out + n / 2);
  106.  
  107.     for (int i = 0; i < n / 2; i++)
  108.         printf("%s\n", out[i].c_str());
  109.  
  110.  
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement