silentkiler029

UVA-10194-Football(aka_Soccer)

Jun 23rd, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.97 KB | None | 0 0
  1. /*  BISMILLAHIR-RAHMANIR-RAHIM
  2.  ____________________________________
  3. |                                    |
  4. |       SHANTO_SUST_SWE-19_029       |
  5. |____________________________________|
  6. */
  7.  
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std;
  11.  
  12. #define ll long long
  13. #define fastio ios_base::sync_with_stdio(false);
  14. #define pb push_back
  15. #define Pi acos(-1)
  16. #define r0 return 0
  17. #define endl "\n"
  18. #define show(x) cout << x << endl
  19. #define take(x) cin >> x
  20. #define debug 1
  21.  
  22. int main()
  23. {
  24.     int n;
  25.     scanf("%d", &n);
  26.     getchar();
  27.     int t, cunt;
  28.     string tournament_name;
  29.     int T, i, j, k, number_of_games, it1, it2;
  30.     char c;
  31.  
  32.     for(t = 1; t <= n; t++) {
  33.         getline(cin, tournament_name);
  34.  
  35.         scanf("%d", &T);
  36.         getchar();
  37.  
  38.         string team_names[T];
  39.         for(i = 0; i < T; i++) {
  40.             getline(cin, team_names[i]);
  41.         }
  42.  
  43.         scanf("%d", &number_of_games);
  44.         getchar();
  45.  
  46.         string game_details[number_of_games];
  47.         for(i = 0; i < number_of_games; i++) {
  48.             getline(cin, game_details[i]);
  49.         }
  50.  
  51.         //input okay (y)
  52.  
  53.         int total_points_earned[T];
  54.         int games_played[T];
  55.         int wins[T];
  56.         int ties[T];
  57.         int losses[T];
  58.         int goal_scored[T];
  59.         int goal_against[T];
  60.  
  61.         for(i = 0; i < T; i++) {
  62.             total_points_earned[i] = 0;
  63.             games_played[i] = 0;
  64.             wins[i] = 0;
  65.             ties[i] = 0;
  66.             losses[i] = 0;
  67.             goal_scored[i] = 0;
  68.             goal_against[i] = 0;
  69.         }
  70.  
  71.         string team1, team2;
  72.         string s1, s2;
  73.         int score1 = 0, score2 = 0;
  74.  
  75.         for(i = 0; i < number_of_games; i++ ) {
  76.             for(j = 0; j < game_details[i].size(); j++) {
  77.                 if(game_details[i][j] == '#') {
  78.                     break;
  79.                 }
  80.                 team1.pb(game_details[i][j]);
  81.             }
  82.             j++;
  83.             for( ; ; j++) {
  84.                 if(game_details[i][j] == '@') {
  85.                     break;
  86.                 }
  87.                 s1.pb(game_details[i][j]);
  88.             }
  89.             j++;
  90.             for( ; ; j++) {
  91.                 if(game_details[i][j] == '#') {
  92.                     break;
  93.                 }
  94.                 s2.pb(game_details[i][j]);
  95.             }
  96.             j++;
  97.             for( ; j < game_details[i].size(); j++) {
  98.                 team2.pb(game_details[i][j]);
  99.             }
  100.  
  101.             score1 = 0, score2 = 0;
  102.  
  103.             for(j = s1.size() - 1, k = 1; j >= 0; j--) {
  104.                 score1 += (s1[j] - '0') * k;
  105.                 k *= 10;
  106.             }
  107.             for(j = s2.size() - 1, k = 1; j >= 0; j--) {
  108.                 score2 += (s2[j] - '0') * k;
  109.                 k *= 10;
  110.             }
  111.             //till now OKAY!
  112.  
  113.             for(j = 0; j < T; j++) {
  114.                 if(team_names[j] == team1) {
  115.                     it1 = j;
  116.                 }
  117.                 else if(team_names[j] == team2) {
  118.                     it2 = j;
  119.                 }
  120.             }
  121.             //till now OKAY!
  122.  
  123.             //calculating points
  124.             if(score1 == score2) {
  125.                 total_points_earned[it1]++;
  126.                 total_points_earned[it2]++;
  127.             }
  128.             else if(score1 > score2) {
  129.                 total_points_earned[it1] += 3;
  130.             }
  131.             else {
  132.                 total_points_earned[it2] += 3;
  133.             }
  134.             //calculating games played
  135.             games_played[it1]++;
  136.             games_played[it2]++;
  137.             //calculating wins & losses & ties
  138.             if(score1 > score2) {
  139.                 wins[it1]++;
  140.                 losses[it2]++;
  141.             }
  142.             else if(score1 < score2) {
  143.                 wins[it2]++;
  144.                 losses[it1]++;
  145.             }
  146.             else {
  147.                 ties[it1]++;
  148.                 ties[it2]++;
  149.             }
  150.             //calculating goal scored
  151.             goal_scored[it1] += score1;
  152.             goal_scored[it2] += score2;
  153.             //calculating goal against
  154.             goal_against[it1] += score2;
  155.             goal_against[it2] += score1;
  156.  
  157.             team1.clear();
  158.             team2.clear();
  159.             s1.clear();
  160.             s2.clear();
  161.         }
  162.  
  163.         int ara[T], temp;
  164.         for(i = 0; i < T; i++) {
  165.             ara[i] = i;
  166.         }
  167.         //most points earned
  168.         for(i = 0; i < T; i++) {
  169.             for(j = i + 1; j < T; j++) {
  170.                 if(total_points_earned[ara[i]] < total_points_earned[ara[j]]) {
  171.                     //swap these two indexed elements of the array between them
  172.                     temp = ara[i];
  173.                     ara[i] = ara[j];
  174.                     ara[j] = temp;
  175.                 }
  176.             }
  177.         }
  178.         //most wins
  179.         int flag, index, l = 0, r;
  180.         for(i = 0; i < T; i++) {
  181.             if(i == T - 1) {
  182.                 r = T;
  183.                 for(j = l; j < r; j++) {
  184.                     for(k = j + 1; k < r; k++) {
  185.                         if( (total_points_earned[ara[i]] == total_points_earned[ara[j]]) &&
  186.                            (wins[ara[j]] < wins[ara[k]]) ) {
  187.                             //swap these two indexed elements of the array between them
  188.                             temp = ara[j];
  189.                             ara[j] = ara[k];
  190.                             ara[k] = temp;
  191.                         }
  192.                     }
  193.                 }
  194.             }
  195.             else if( total_points_earned[ara[i]] != total_points_earned[ara[l]] ) {
  196.                 r = i;
  197.                 for(j = l; j < r; j++) {
  198.                     for(k = j + 1; k < r; k++) {
  199.                         if(wins[ara[j]] < wins[ara[k]]) {
  200.                             //swap these two indexed elements of the array between them
  201.                             temp = ara[j];
  202.                             ara[j] = ara[k];
  203.                             ara[k] = temp;
  204.                         }
  205.                     }
  206.                 }
  207.                 l = r;
  208.             }
  209.         }
  210.         //most goal difference
  211.         l = 0;
  212.         for(i = 0; i < T; i++) {
  213.             if(i == T - 1) {
  214.                 r = T;
  215.                 for(j = l; j < r; j++) {
  216.                     for(k = j + 1; k < r; k++) {
  217.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  218.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) < (goal_scored[ara[k]] - goal_against[ara[k]]) ) ) {
  219.                             //swap
  220.                             temp = ara[j];
  221.                             ara[j] = ara[k];
  222.                             ara[k] = temp;
  223.                         }
  224.                     }
  225.                 }
  226.             }
  227.             else if( wins[ara[i]] != wins[ara[l]] ) {
  228.                 r = i;
  229.                 for(j = l; j < r; j++) {
  230.                     for(k = j + 1; k < r; k++) {
  231.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  232.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) < (goal_scored[ara[k]] - goal_against[ara[k]]) ) ) {
  233.                             //swap
  234.                             temp = ara[j];
  235.                             ara[j] = ara[k];
  236.                             ara[k] = temp;
  237.                         }
  238.                     }
  239.                 }
  240.                 l = r;
  241.             }
  242.         }
  243.         //most goals scored
  244.         l = 0;
  245.         for(i = 0; i < T; i++) {
  246.             if(i == T - 1) {
  247.                 r = T;
  248.                 for(j = l; j < r; j++) {
  249.                     for(k = j + 1; k < r; k++) {
  250.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  251.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
  252.                            ( goal_scored[ara[j]] < goal_scored[ara[k]] ) ) {
  253.                             //swap
  254.                             temp = ara[j];
  255.                             ara[j] = ara[k];
  256.                             ara[k] = temp;
  257.                         }
  258.                     }
  259.                 }
  260.             }
  261.             else if( goal_scored[ara[i]] - goal_against[ara[i]] != goal_scored[ara[l]] - goal_against[ara[l]] ) {
  262.                 r = i;
  263.                 for(j = l; j < r; j++) {
  264.                     for(k = j + 1; k < r; k++) {
  265.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  266.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
  267.                            ( goal_scored[ara[j]] < goal_scored[ara[k]] ) ) {
  268.                             //swap
  269.                             temp = ara[j];
  270.                             ara[j] = ara[k];
  271.                             ara[k] = temp;
  272.                         }
  273.                     }
  274.                 }
  275.                 l = r;
  276.             }
  277.         }
  278.         //less game played
  279.         l = 0;
  280.         for(i = 0; i < T; i++) {
  281.             if(i == T - 1) {
  282.                 r = T;
  283.                 for(j = l; j < r; j++) {
  284.                     for(k = j + 1; k < r; k++) {
  285.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  286.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
  287.                            ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
  288.                            ( games_played[ara[j]] > games_played[ara[k]] ) ) {
  289.                             //swap
  290.                             temp = ara[j];
  291.                             ara[j] = ara[k];
  292.                             ara[k] = temp;
  293.                         }
  294.                     }
  295.                 }
  296.             }
  297.             else if( goal_scored[ara[i]] != goal_scored[ara[l]] ) {
  298.                 r = i;
  299.                 for(j = l; j < r; j++) {
  300.                     for(k = j + 1; k < r; k++) {
  301.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  302.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
  303.                            ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
  304.                            ( games_played[ara[j]] > games_played[ara[k]] ) ) {
  305.                             //swap
  306.                             temp = ara[j];
  307.                             ara[j] = ara[k];
  308.                             ara[k] = temp;
  309.                         }
  310.                     }
  311.                 }
  312.                 l = r;
  313.             }
  314.         }
  315.  
  316.         string temp1, temp2;
  317.         int i;
  318.  
  319.  
  320.         //lexicographic order
  321.         l = 0;
  322.         for(i = 0; i < T; i++) {
  323.             if(i == T - 1) {
  324.                 r = T;
  325.                 for(j = l; j < r; j++) {
  326.                     for(k = j + 1; k < r; k++) {
  327.                         for(l = 0; l < team_names[ara[j]].size(); l++) {
  328.                             if( (team_names[ara[j]][l] >= 65 && team_names[ara[j]][l] <= 90) ) {
  329.                                 temp1.pb(team_names[ara[j]][l] | 32);
  330.                             }
  331.                             else {
  332.                                 temp1.pb(team_names[ara[j]][l]);
  333.                             }
  334.                         }
  335.                         for(l = 0; l < team_names[ara[k]].size(); l++) {
  336.                             if( (team_names[ara[k]][l] >= 65 && team_names[ara[k]][l] <= 90) ) {
  337.                                 temp2.pb(team_names[ara[k]][l] | 32);
  338.                             }
  339.                             else {
  340.                                 temp2.pb(team_names[ara[k]][l]);
  341.                             }
  342.                         }
  343.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  344.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
  345.                            ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
  346.                            ( games_played[ara[j]] == games_played[ara[k]] ) &&
  347.                            ( temp1 > temp2 ) ) {
  348.                             //swap
  349.                             temp = ara[j];
  350.                             ara[j] = ara[k];
  351.                             ara[k] = temp;
  352.                         }
  353.                         temp1.clear();
  354.                         temp2.clear();
  355.                     }
  356.                 }
  357.             }
  358.             else if( games_played[ara[i]] != games_played[ara[l]] ) {
  359.                 r = i;
  360.                 for(j = l; j < r; j++) {
  361.                     for(k = j + 1; k < r; k++) {
  362.                         for(l = 0; l < team_names[ara[j]].size(); l++) {
  363.                             if( (team_names[ara[j]][l] >= 65 && team_names[ara[j]][l] <= 90) ) {
  364.                                 temp1.pb(team_names[ara[j]][l] | 32);
  365.                             }
  366.                             else {
  367.                                 temp1.pb(team_names[ara[j]][l]);
  368.                             }
  369.                         }
  370.                         for(l = 0; l < team_names[ara[k]].size(); l++) {
  371.                             if( (team_names[ara[k]][l] >= 65 && team_names[ara[k]][l] <= 90) ) {
  372.                                 temp2.pb(team_names[ara[k]][l] | 32);
  373.                             }
  374.                             else {
  375.                                 temp2.pb(team_names[ara[k]][l]);
  376.                             }
  377.                         }
  378.                         if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
  379.                            ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
  380.                            ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
  381.                            ( games_played[ara[j]] == games_played[ara[k]] ) &&
  382.                            ( temp1 > temp2 ) ) {
  383.                             //swap
  384.                             temp = ara[j];
  385.                             ara[j] = ara[k];
  386.                             ara[k] = temp;
  387.                         }
  388.                         temp1.clear();
  389.                         temp2.clear();
  390.                     }
  391.                 }
  392.                 l = r;
  393.             }
  394.         }
  395.  
  396.  
  397.  
  398.         if(t != 1) {
  399.             cout << endl;
  400.         }
  401.         cout << tournament_name << endl;
  402.  
  403.         for(i = 0; i < T; i++) {
  404.             cout << i + 1 << ") ";
  405.             cout << team_names[ara[i]] << " ";
  406.             cout << total_points_earned[ara[i]] << "p, ";
  407.             cout << games_played[ara[i]]<< "g (";
  408.             cout << wins[ara[i]]<< "-";
  409.             cout << ties[ara[i]]<< "-";
  410.             cout << losses[ara[i]]<< "), ";
  411.             cout << goal_scored[ara[i]] - goal_against[ara[i]] << "gd (";
  412.             cout << goal_scored[ara[i]] << "-";
  413.             cout << goal_against[ara[i]] << ")" << endl;
  414.         }
  415.     }
  416.  
  417.  
  418.     r0;
  419. }
  420.  
  421. //ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment