csansoon

X88161 Classificació de la lliga

Feb 15th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct Partit{
  7.     int x;
  8.     int y;
  9. };
  10. struct outputs{
  11.     int name;
  12.     int total;
  13.     int goals;
  14.     int lost;
  15. };
  16. typedef vector <vector <Partit> > scoretable;
  17.  
  18.  
  19. bool comp(const outputs& a, const outputs& b) {
  20.     if (a.total != b.total) return a.total > b.total;
  21.     int ag = a.goals - a.lost;
  22.     int bg = b.goals - b.lost;
  23.     if (ag != bg) return ag > bg;
  24.     return a.name < b.name;
  25. }
  26.  
  27.  
  28. scoretable read_scores() {
  29.     int n;
  30.     cin >> n;
  31.     scoretable score(n,(vector <Partit> (n)));
  32.     for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) cin >> score[i][j].x >> score[i][j].y;
  33.     return score;
  34. }
  35.  
  36.  
  37. vector <outputs> team_scores(const scoretable& score) {
  38.     vector <outputs> out(0);
  39.     int n = score[0].size();
  40.     for (int t=0; t<n; ++t) {
  41.         outputs o;
  42.         o.name = t+1;
  43.         o.total = 0;
  44.         o.goals = 0;
  45.         o.lost = 0;
  46.         for (int i=0; i<n; ++i) {
  47.             if (t!=i) {
  48.                 //total
  49.                 if          (score[t][i].x > score[t][i].y) o.total += 3;
  50.                 else if     (score[t][i].x == score[t][i].y) o.total += 1;
  51.                 if          (score[i][t].y > score[i][t].x) o.total += 3;
  52.                 else if     (score[i][t].y == score[i][t].x) o.total += 1;
  53.                 //goals
  54.                 o.goals = o.goals + score[t][i].x + score[i][t].y;
  55.                 //lost
  56.                 o.lost = o.lost + score[t][i].y + score[i][t].x;
  57.             }
  58.         }
  59.         out.push_back(o);
  60.     }
  61.     sort(out.begin(), out.end(), comp);
  62.     return out;
  63. }
  64.  
  65.  
  66. void print_scores(const vector <outputs>& out) {
  67.     int n = out.size();
  68.     for (int i=0; i<n; ++i) cout << out[i].name << " " << out[i].total << " " << out[i].goals << " " << out[i].lost << endl;
  69. }
  70.  
  71.  
  72. int main() {
  73.     scoretable score = read_scores();
  74.     vector <outputs> out = team_scores(score);
  75.     print_scores(out);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment