Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <iomanip>
- using namespace std;
- struct team
- {
- string name;
- int played, won, drawn, lost, points, goals, goalsa, diff;
- team(): played(0), won(0), drawn(0), lost(0), points(0), goals(0), goalsa(0), diff(0) {};
- };
- void sortin (struct team *p, struct team *q);
- void swapr (struct team *p, struct team *q);
- int main ()
- {
- string tournament, line, tm1, tm2;
- int T, G, i, j, tm1g, tm2g;
- //Taking name of the Tournament
- cout << "Name of the Tournament: ";
- getline (cin, tournament);
- //Taking input for Team Number
- cout << "How many Teams? ";
- getline (cin, line);
- stringstream (line) >> T;
- //Setting up Array Size for Teams
- struct team tm[T], tts;
- for (i = 0; i < T; i++)
- getline (cin, tm[i].name);
- //Taking input for the Number of Games Already Played
- cout << "Total Games Played in the Tournament: ";
- getline (cin, line);
- stringstream (line) >> G;
- //Taking Scores
- while (G--)
- {
- getline (cin, tm1);
- getline (cin, line);
- stringstream (line) >> tm1g;
- getline (cin, tm2);
- getline (cin, line);
- stringstream (line) >> tm2g;
- //Checking Team Match and Updating Scores
- for (i = 0; i < T; i++)
- if (tm[i].name == tm1)
- {
- tm[i].played++;
- if (tm1g > tm2g)
- {
- tm[i].won++;
- tm[i].points += 3;
- tm[i].goals += tm1g;
- tm[i].goalsa += tm2g;
- tm[i].diff += (tm1g - tm2g);
- }
- else if (tm1g < tm2g)
- {
- tm[i].lost++;
- tm[i].goals += tm1g;
- tm[i].goalsa += tm2g;
- tm[i].diff += (tm1g - tm2g);
- }
- else
- {
- tm[i].drawn++;
- tm[i].points++;
- tm[i].goals += tm1g;
- tm[i].goalsa += tm2g;
- }
- break;
- }
- for (i = 0; i < T; i++)
- if (tm[i].name == tm2)
- {
- tm[i].played++;
- if (tm2g > tm1g)
- {
- tm[i].won++;
- tm[i].points += 3;
- tm[i].goals += tm2g;
- tm[i].goalsa += tm1g;
- tm[i].diff += (tm2g - tm1g);
- }
- else if (tm2g < tm1g)
- {
- tm[i].lost++;
- tm[i].goals += tm2g;
- tm[i].goalsa += tm1g;
- tm[i].diff += (tm2g - tm1g);
- }
- else
- {
- tm[i].drawn++;
- tm[i].points += 1;
- tm[i].goals += tm2g;
- tm[i].goalsa += tm1g;
- }
- break;
- }
- }
- //Sorting
- for (i = 0; i < T - 1; i++)
- for (j = i + 1; j < T; j++)
- sortin (&tm[i], &tm[j]);
- //printing Scores
- cout << endl << tournament << endl << left << setw(6) << "Pos." << left << setw(15) << "Team Name" << right << setw(7) << "Played" << right << setw(4) << "Won" << right << setw(6) << "Drawn" << right << setw(5) << "Lost" << right << setw(7) << "Points" << right << setw(13) << "Goals (F/A)" << right << setw(5) << "Diff" << endl;
- for (i = 0; i < T; i++)
- cout << left << setw(6) << i+1 << left << setw(15) << tm[i].name << right << setw(7) << tm[i].played << right << setw(4) << tm[i].won << right << setw(6) << tm[i].drawn << right << setw(5) << tm[i].lost << right << setw(7) << tm[i].points << right << setw(11) << tm[i].goals << "/" << tm[i].goalsa << right << setw(5) << tm[i].diff << endl;
- cout << endl;
- return 0;
- }
- //Swapping Function
- void swapr (struct team *p, struct team *q)
- {
- struct team t;
- t = *p;
- *p = *q;
- *q = t;
- return;
- }
- //Sorting Function
- void sortin (struct team *p, struct team *q)
- {
- if ((*p).points < (*q).points)
- swapr(p,q);
- else if (((*p).won < (*q).won) && ((*p).points == (*q).points))
- swapr(p,q);
- else if (((*p).diff < (*q).diff) && ((*p).won == (*q).won) && ((*p).points == (*q).points))
- swapr(p,q);
- else if (((*p).won < (*q).goals) && ((*p).diff == (*q).diff) && ((*p).won == (*q).won) && ((*p).points == (*q).points))
- swapr(p,q);
- else if (((*p).played > (*q).played) && ((*p).won < (*q).goals) && ((*p).diff == (*q).diff) && ((*p).won == (*q).won) && ((*p).points == (*q).points))
- swapr(p,q);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement