Advertisement
JosepRivaille

X88161: Classificació de la lliga

Sep 18th, 2015
1,735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct Match {
  7.     int x, y;
  8. };
  9.  
  10. typedef vector<Match> Row;
  11. typedef vector<Row> Matrix;
  12.  
  13. typedef vector<int> Fila;
  14. typedef vector<Fila> Matriu;
  15.  
  16. void read_matrix(Matrix& M) {
  17.     int tam = M.size();
  18.     for (int i = 0; i < tam; ++i) {
  19.         for (int j = 0; j < tam; ++j) {
  20.             cin >> M[i][j].x >> M[i][j].y;
  21.         }
  22.     }
  23. }
  24.  
  25. void def_matrix (Matriu& R, const Matrix& M) {
  26.     int tam = R.size();
  27.     //NÄ‚ÅŸmero equip
  28.     for (int i = 0; i < tam; ++i) R[i][0] = i+1;
  29.     //Puntuacio
  30.     for (int i = 0; i < tam; ++i) {
  31.         for (int j = 0; j < tam; ++j) {
  32.             if (i != j) {
  33.                 //Punts
  34.                 if (M[i][j].x == M[i][j].y) {
  35.                     ++R[i][1];
  36.                     ++R[j][1];
  37.                 }
  38.                 else if (M[i][j].x > M[i][j].y) R[i][1] += 3;
  39.                 else R[j][1] += 3;
  40.                 //Gols
  41.                     //Favor
  42.                     R[i][2] += M[i][j].x;
  43.                     R[j][2] += M[i][j].y;
  44.                     //Contra
  45.                     R[i][3] += M[i][j].y;
  46.                     R[j][3] += M[i][j].x;
  47.             }
  48.         }
  49.     }
  50. }
  51.  
  52. bool comp(const vector<int>& v, const vector<int>& u) {
  53.     if (v[1] == u[1]) {
  54.         if (v[2]-v[3] == u[2]-u[3]) {
  55.             return v[0] < u[0];
  56.         }
  57.         else return v[2]-v[3] > u[2]-u[3];
  58.     }
  59.     else return v[1] > u[1];
  60. }
  61.  
  62. void write_matrix(const Matriu& R) {
  63.     int tam = R.size();
  64.     for (int i = 0; i < tam; ++i) {
  65.         for (int j = 0; j < 4; ++j) {
  66.             if (j != 0) cout << " ";
  67.             cout << R[i][j];
  68.         } cout << endl;
  69.     }
  70. }
  71.  
  72.  
  73. int main() {
  74.     int n;
  75.     cin >> n;
  76.     Matrix M(n, Row(n));
  77.     read_matrix(M);
  78.     Matriu R(n, Fila(4, 0));
  79.     def_matrix(R, M);
  80.     sort(R.begin(), R.end(), comp);
  81.     write_matrix(R);
  82. }
  83.  
  84. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement