Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int numberOfTournaments, startPoints;
- cin >> numberOfTournaments >> startPoints;
- int tournamentPoints = 0;
- int gamesWon = 0;
- string currentTournament;
- for (int i = 0; i < numberOfTournaments; i++) {
- cin >> currentTournament;
- if (currentTournament == "W") {
- tournamentPoints += 2000;
- gamesWon++;
- }
- else if (currentTournament == "F") {
- tournamentPoints += 1200;
- }
- else {
- tournamentPoints += 720;
- }
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << "Final points: " << startPoints + tournamentPoints << endl;
- cout << "Average points: " << tournamentPoints / numberOfTournaments << endl;
- cout << 100.0 * gamesWon / numberOfTournaments << '%' << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int numberOfTournaments, startPoints;
- cin >> numberOfTournaments >> startPoints;
- int tournamentPoints = 0;
- int gamesWon = 0;
- string currentTournament;
- for (int i = 0; i < numberOfTournaments; i++) {
- cin >> currentTournament;
- tournamentPoints +=
- currentTournament == "W" ? 2000 :
- currentTournament == "F" ? 1200 : 720;
- if (currentTournament == "W") {
- gamesWon++;
- }
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << "Final points: " << startPoints + tournamentPoints << endl;
- cout << "Average points: " << tournamentPoints / numberOfTournaments << endl;
- cout << 100.0 * gamesWon / numberOfTournaments << '%' << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement