Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- const size_t nTeams = 5;
- struct FootballChampionship
- {
- size_t table[nTeams][nTeams];
- string teamNames[nTeams];
- void print()
- {
- cout << "Table:" << endl;
- for (size_t i = 0; i < nTeams; i++)
- {
- for (size_t j = 0; j < nTeams; j++)
- {
- cout << setw(3) << table[i][j];
- }
- cout << endl;
- }
- };
- void fill()
- {
- cout << "Enter the names of teams:" << endl;
- for (size_t i = 0; i < nTeams; i++)
- {
- cout << i + 1 << ") ";
- getline(cin, teamNames[i]);
- }
- cout << endl << "Fill table:" << endl;
- for (size_t i = 0; i < nTeams; i++)
- for (size_t j = 0; j < nTeams; j++)
- if (i != j)
- cin >> table[i][j];
- else
- table[i][j] = 0;
- }
- //a
- string getWinMoreLose()
- {
- string str;
- size_t lose, win;
- for (size_t i = 0; i < nTeams; i++)
- {
- lose = win = 0;
- for (size_t j = 0; j < nTeams; j++)
- if (i != j)
- {
- if (table[i][j] == 3)
- win++;
- else if (table[i][j] == 0)
- lose++;
- }
- if (win > lose)
- str += teamNames[i] + "; ";
- }
- return str;
- }
- //b
- string getWithoutLose()
- {
- string str;
- for (size_t i = 0; i < nTeams; i++)
- {
- bool isFailed = false;
- for (size_t j = 0; j < nTeams; j++)
- if (i != j && table[i][j] == 0)
- {
- isFailed = true;
- break;
- }
- if (!isFailed)
- str += teamNames[i] + "; ";
- }
- return str;
- };
- //B
- string getWinner()
- {
- size_t iMax = 0, sMax = 0;
- for (size_t i = 0; i < nTeams; i++)
- {
- size_t sCurr = _getTeamScore(i);
- if (sCurr > sMax)
- {
- iMax = i;
- sMax = sCurr;
- }
- }
- return teamNames[iMax];
- }
- //C
- bool isSorted()
- {
- for (size_t i = 0; i < nTeams - 1; i++)
- if (_getTeamScore(i) < _getTeamScore(i + 1))
- return false;
- return true;
- };
- //helping void
- size_t _getTeamScore(size_t id)
- {
- size_t score = 0;
- for (size_t j = 0; j < nTeams; j++)
- if (id != j)
- score += table[id][j];
- return score;
- }
- };
- int main()
- {
- FootballChampionship s;
- s.fill();
- cout << endl;
- s.print();
- cout << endl << "Teams, that have more wins neither loses: " << s.getWinMoreLose();
- cout << endl << "Teams, that didn't lose: " << s.getWithoutLose();
- cout << endl << "Team winner: " << s.getWinner();
- cout << endl << "Is sorteb by places: " << s.isSorted();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment