Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* BISMILLAHIR-RAHMANIR-RAHIM
- ____________________________________
- | |
- | SHANTO_SUST_SWE-19_029 |
- |____________________________________|
- */
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fastio ios_base::sync_with_stdio(false);
- #define pb push_back
- #define Pi acos(-1)
- #define r0 return 0
- #define endl "\n"
- #define show(x) cout << x << endl
- #define take(x) cin >> x
- #define debug 1
- int main()
- {
- int n;
- scanf("%d", &n);
- getchar();
- int t, cunt;
- string tournament_name;
- int T, i, j, k, number_of_games, it1, it2;
- char c;
- for(t = 1; t <= n; t++) {
- getline(cin, tournament_name);
- scanf("%d", &T);
- getchar();
- string team_names[T];
- for(i = 0; i < T; i++) {
- getline(cin, team_names[i]);
- }
- scanf("%d", &number_of_games);
- getchar();
- string game_details[number_of_games];
- for(i = 0; i < number_of_games; i++) {
- getline(cin, game_details[i]);
- }
- //input okay (y)
- int total_points_earned[T];
- int games_played[T];
- int wins[T];
- int ties[T];
- int losses[T];
- int goal_scored[T];
- int goal_against[T];
- for(i = 0; i < T; i++) {
- total_points_earned[i] = 0;
- games_played[i] = 0;
- wins[i] = 0;
- ties[i] = 0;
- losses[i] = 0;
- goal_scored[i] = 0;
- goal_against[i] = 0;
- }
- string team1, team2;
- string s1, s2;
- int score1 = 0, score2 = 0;
- for(i = 0; i < number_of_games; i++ ) {
- for(j = 0; j < game_details[i].size(); j++) {
- if(game_details[i][j] == '#') {
- break;
- }
- team1.pb(game_details[i][j]);
- }
- j++;
- for( ; ; j++) {
- if(game_details[i][j] == '@') {
- break;
- }
- s1.pb(game_details[i][j]);
- }
- j++;
- for( ; ; j++) {
- if(game_details[i][j] == '#') {
- break;
- }
- s2.pb(game_details[i][j]);
- }
- j++;
- for( ; j < game_details[i].size(); j++) {
- team2.pb(game_details[i][j]);
- }
- score1 = 0, score2 = 0;
- for(j = s1.size() - 1, k = 1; j >= 0; j--) {
- score1 += (s1[j] - '0') * k;
- k *= 10;
- }
- for(j = s2.size() - 1, k = 1; j >= 0; j--) {
- score2 += (s2[j] - '0') * k;
- k *= 10;
- }
- //till now OKAY!
- for(j = 0; j < T; j++) {
- if(team_names[j] == team1) {
- it1 = j;
- }
- else if(team_names[j] == team2) {
- it2 = j;
- }
- }
- //till now OKAY!
- //calculating points
- if(score1 == score2) {
- total_points_earned[it1]++;
- total_points_earned[it2]++;
- }
- else if(score1 > score2) {
- total_points_earned[it1] += 3;
- }
- else {
- total_points_earned[it2] += 3;
- }
- //calculating games played
- games_played[it1]++;
- games_played[it2]++;
- //calculating wins & losses & ties
- if(score1 > score2) {
- wins[it1]++;
- losses[it2]++;
- }
- else if(score1 < score2) {
- wins[it2]++;
- losses[it1]++;
- }
- else {
- ties[it1]++;
- ties[it2]++;
- }
- //calculating goal scored
- goal_scored[it1] += score1;
- goal_scored[it2] += score2;
- //calculating goal against
- goal_against[it1] += score2;
- goal_against[it2] += score1;
- team1.clear();
- team2.clear();
- s1.clear();
- s2.clear();
- }
- int ara[T], temp;
- for(i = 0; i < T; i++) {
- ara[i] = i;
- }
- //most points earned
- for(i = 0; i < T; i++) {
- for(j = i + 1; j < T; j++) {
- if(total_points_earned[ara[i]] < total_points_earned[ara[j]]) {
- //swap these two indexed elements of the array between them
- temp = ara[i];
- ara[i] = ara[j];
- ara[j] = temp;
- }
- }
- }
- //most wins
- int flag, index, l = 0, r;
- for(i = 0; i < T; i++) {
- if(i == T - 1) {
- r = T;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if( (total_points_earned[ara[i]] == total_points_earned[ara[j]]) &&
- (wins[ara[j]] < wins[ara[k]]) ) {
- //swap these two indexed elements of the array between them
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- }
- else if( total_points_earned[ara[i]] != total_points_earned[ara[l]] ) {
- r = i;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if(wins[ara[j]] < wins[ara[k]]) {
- //swap these two indexed elements of the array between them
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- l = r;
- }
- }
- //most goal difference
- l = 0;
- for(i = 0; i < T; i++) {
- if(i == T - 1) {
- r = T;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) < (goal_scored[ara[k]] - goal_against[ara[k]]) ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- }
- else if( wins[ara[i]] != wins[ara[l]] ) {
- r = i;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) < (goal_scored[ara[k]] - goal_against[ara[k]]) ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- l = r;
- }
- }
- //most goals scored
- l = 0;
- for(i = 0; i < T; i++) {
- if(i == T - 1) {
- r = T;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
- ( goal_scored[ara[j]] < goal_scored[ara[k]] ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- }
- else if( goal_scored[ara[i]] - goal_against[ara[i]] != goal_scored[ara[l]] - goal_against[ara[l]] ) {
- r = i;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
- ( goal_scored[ara[j]] < goal_scored[ara[k]] ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- l = r;
- }
- }
- //less game played
- l = 0;
- for(i = 0; i < T; i++) {
- if(i == T - 1) {
- r = T;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
- ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
- ( games_played[ara[j]] > games_played[ara[k]] ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- }
- else if( goal_scored[ara[i]] != goal_scored[ara[l]] ) {
- r = i;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
- ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
- ( games_played[ara[j]] > games_played[ara[k]] ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- }
- }
- l = r;
- }
- }
- string temp1, temp2;
- int i;
- //lexicographic order
- l = 0;
- for(i = 0; i < T; i++) {
- if(i == T - 1) {
- r = T;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- for(l = 0; l < team_names[ara[j]].size(); l++) {
- if( (team_names[ara[j]][l] >= 65 && team_names[ara[j]][l] <= 90) ) {
- temp1.pb(team_names[ara[j]][l] | 32);
- }
- else {
- temp1.pb(team_names[ara[j]][l]);
- }
- }
- for(l = 0; l < team_names[ara[k]].size(); l++) {
- if( (team_names[ara[k]][l] >= 65 && team_names[ara[k]][l] <= 90) ) {
- temp2.pb(team_names[ara[k]][l] | 32);
- }
- else {
- temp2.pb(team_names[ara[k]][l]);
- }
- }
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
- ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
- ( games_played[ara[j]] == games_played[ara[k]] ) &&
- ( temp1 > temp2 ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- temp1.clear();
- temp2.clear();
- }
- }
- }
- else if( games_played[ara[i]] != games_played[ara[l]] ) {
- r = i;
- for(j = l; j < r; j++) {
- for(k = j + 1; k < r; k++) {
- for(l = 0; l < team_names[ara[j]].size(); l++) {
- if( (team_names[ara[j]][l] >= 65 && team_names[ara[j]][l] <= 90) ) {
- temp1.pb(team_names[ara[j]][l] | 32);
- }
- else {
- temp1.pb(team_names[ara[j]][l]);
- }
- }
- for(l = 0; l < team_names[ara[k]].size(); l++) {
- if( (team_names[ara[k]][l] >= 65 && team_names[ara[k]][l] <= 90) ) {
- temp2.pb(team_names[ara[k]][l] | 32);
- }
- else {
- temp2.pb(team_names[ara[k]][l]);
- }
- }
- if( (total_points_earned[ara[j]] == total_points_earned[ara[k]]) &&
- ( (goal_scored[ara[j]] - goal_against[ara[j]]) == (goal_scored[ara[k]] - goal_against[ara[k]]) ) &&
- ( goal_scored[ara[j]] == goal_scored[ara[k]] ) &&
- ( games_played[ara[j]] == games_played[ara[k]] ) &&
- ( temp1 > temp2 ) ) {
- //swap
- temp = ara[j];
- ara[j] = ara[k];
- ara[k] = temp;
- }
- temp1.clear();
- temp2.clear();
- }
- }
- l = r;
- }
- }
- if(t != 1) {
- cout << endl;
- }
- cout << tournament_name << endl;
- for(i = 0; i < T; i++) {
- cout << i + 1 << ") ";
- cout << team_names[ara[i]] << " ";
- cout << total_points_earned[ara[i]] << "p, ";
- cout << games_played[ara[i]]<< "g (";
- cout << wins[ara[i]]<< "-";
- cout << ties[ara[i]]<< "-";
- cout << losses[ara[i]]<< "), ";
- cout << goal_scored[ara[i]] - goal_against[ara[i]] << "gd (";
- cout << goal_scored[ara[i]] << "-";
- cout << goal_against[ara[i]] << ")" << endl;
- }
- }
- r0;
- }
- //ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment