daily pastebin goal
96%
SHARE
TWEET

UCL Author

deadwing97 Mar 25th, 2019 281 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. #define Integer long long int
  7. #define TRACE(x) cout    << #x << " : " << x << endl
  8. using namespace std;
  9.  
  10. const string digit = "0123456789";
  11. const string letter = "abcdefg_hijklmnop_qrs_tuv_wx_yz_ABCDEFG_HIJKLMNOP_QRS_TUV_WX_YZ";
  12. const char zero = '0';
  13. const int matchNumber = 12;
  14. const int teamNumber = 4;
  15. vector<string> name;
  16. Integer score[teamNumber];
  17. Integer goals[teamNumber];
  18. Integer goalDiff[teamNumber];
  19. Integer awaygoal[teamNumber];
  20.  
  21. void clear() {
  22.     name.clear();
  23.     for (int i = 0; i < teamNumber; i++) {
  24.         score[i] = 0;
  25.         goals[i] = 0;
  26.         goalDiff[i] = 0;
  27.         awaygoal[i] = 0;
  28.     }
  29. }
  30.  
  31. int first(const string &str, int s_index, const string &match) {
  32.     for (int i = s_index; i < str.size(); i++) {
  33.         char c = str[i];
  34.         for (int j = 0; j < match.size(); j++)
  35.             if (c == match[j])
  36.                 return i;
  37.     }
  38.     return -1;
  39. }
  40.  
  41. bool isDigit(char c) {
  42.     for (int i = 0; i < digit.size(); i++)
  43.         if (c == digit[i])
  44.             return true;
  45.     return false;
  46. }
  47.  
  48. pair<string, string> extractTeams(const string &line) {
  49.     pair<string, string> res;
  50.     int fd = first(line, 0, digit) - 2;
  51.     res.first = line.substr(0, fd + 1);
  52.     int dot = first(line, 0, ".");
  53.     int beg = first(line, dot, letter);
  54.     if (!isDigit(line[beg - 2]))
  55.         beg--;
  56.     res.second = line.substr(beg);
  57.     return res;
  58. }
  59.  
  60. pair<Integer, Integer> extractGoals(const string &line) {
  61.     pair<Integer, Integer> res;
  62.     Integer n = 0;
  63.     int ind = first(line, 0, digit);
  64.     while (isDigit(line[ind])) {
  65.         int val = int(line[ind]) - int(zero);
  66.         n *= 10;
  67.         n += val;
  68.         ind++;
  69.     }
  70.     res.first = n;
  71.     n = 0;
  72.     int dot = first(line, 0, ".");
  73.     ind = first(line, dot, digit);
  74.     while (isDigit(line[ind])) {
  75.         int val = int(line[ind]) - int(zero);
  76.         n *= 10;
  77.         n += val;
  78.         ind++;
  79.     }
  80.     res.second = n;
  81.     return res;
  82. }
  83.  
  84. int numberOfTeam(string team) {
  85.     for (int i = 0; i < name.size(); i++)
  86.         if (team == name[i])
  87.             return i;
  88.     return -1;
  89. }
  90.  
  91. void update(int a, int b, Integer c, Integer d) {
  92.     goals[a] += c;
  93.     goals[b] += d;
  94.     goalDiff[a] += c - d;
  95.     goalDiff[b] += d - c;
  96.     awaygoal[b] += d;
  97.     if (c == d) {
  98.         score[a]++;
  99.         score[b]++;
  100.     } else if (c > d)
  101.         score[a] += 3;
  102.     else
  103.         score[b] += 3;
  104.     if (a == 0 || b == 0) {
  105. //        TRACE(a);
  106. //        TRACE(b);
  107. //        TRACE(c);
  108. //        TRACE(d);
  109. //        TRACE(score[0]);
  110. //        cout<<"---------------\n";
  111.     }
  112. }
  113.  
  114. void read() {
  115.     for (int i = 0; i < matchNumber; i++) {
  116.         string line;
  117.         getline(cin, line);
  118.         pair<string, string> teams = extractTeams(line);
  119.         string homeTeam = teams.first;
  120.         string awayTeam = teams.second;
  121.         int a = numberOfTeam(homeTeam);
  122.         if (a == -1) {
  123.             name.push_back(homeTeam);
  124.             a = name.size() - 1;
  125.         }
  126.         int b = numberOfTeam(awayTeam);
  127.         if (b == -1) {
  128.             name.push_back(awayTeam);
  129.             b = name.size() - 1;
  130.         }
  131.         pair<Integer, Integer> goals = extractGoals(line);
  132.         Integer c = goals.first;
  133.         Integer d = goals.second;
  134.         update(a, b, c, d);
  135.     }
  136. }
  137.  
  138. bool outRank(int a, int b) {
  139.     if (score[a] == score[b]) {
  140.         if (goalDiff[a] == goalDiff[b]) {
  141.             if (goals[a] == goals[b])
  142.                 return (awaygoal[a] > awaygoal[b]);
  143.             else
  144.                 return (goals[a] > goals[b]);
  145.         } else
  146.             return (goalDiff[a] > goalDiff[b]);
  147.     } else
  148.         return (score[a] > score[b]);
  149. }
  150.  
  151. int best() {
  152.     int res = 0;
  153.     for (int i = 1; i < teamNumber; i++)
  154.         if (outRank(i, res))
  155.             res = i;
  156.     return res;
  157. }
  158.  
  159. int best(int firstTeam) {
  160.     int res = 0;
  161.     if (firstTeam == 0)
  162.         res = 1;
  163.     for (int i = 1; i < teamNumber; i++) {
  164.         if (i == firstTeam)
  165.             continue;
  166.         if (outRank(i, res))
  167.             res = i;
  168.     }
  169.     return res;
  170. }
  171.  
  172.  
  173. int main() {
  174.     int t;
  175.     cin>>t;
  176.     string x;
  177.     getline(cin,x);
  178.     for (int i = 0; i < t; i++) {
  179.         clear();
  180.         read();
  181.         int firstTeam = best();
  182.         int secondTeam = best(firstTeam);
  183. //    TRACE(firstTeam);
  184. //    TRACE(name[firstTeam]);
  185. //    TRACE(score[firstTeam]);
  186. //    TRACE(goalDiff[firstTeam]);
  187. //    TRACE(awaygoal[firstTeam]);
  188. //    TRACE(secondTeam);
  189. //    TRACE(name[secondTeam]);
  190. //    TRACE(score[secondTeam]);
  191. //    TRACE(goalDiff[secondTeam]);
  192. //    TRACE(awaygoal[secondTeam]);
  193. //    cout << outRank(firstTeam, secondTeam) << endl;
  194.         cout << name[firstTeam] <<" ";
  195.         cout << name[secondTeam] << endl;
  196.     }
  197.     return 0;
  198. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top