Advertisement
Spocoman

Football Tournament

Sep 19th, 2023
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string team, result;
  9.     getline(cin, team);
  10.  
  11.     int matchCount, won = 0, drawn = 0, lost = 0;
  12.     cin >> matchCount;
  13.  
  14.     for (int i = 0; i < matchCount; i++) {
  15.         cin >> result;
  16.         if (result == "W") {
  17.             won++;
  18.         }
  19.         else if (result == "D") {
  20.             drawn++;
  21.         }
  22.         else {
  23.             lost++;
  24.         }
  25.     }
  26.  
  27.     if (matchCount == 0) {
  28.         cout << team << " hasn't played any games during this season.\n";
  29.     }
  30.     else {
  31.         cout << team << " has won " << won * 3 + drawn << " points during this season.\n"
  32.             << "Total stats:\n"
  33.             << "## W: " << won << "\n"
  34.             << "## D: " << drawn << "\n"
  35.             << "## L: " << lost << "\n"
  36.             << "Win rate: " << fixed << setprecision(2) << 100.0 * won / matchCount << "%\n";
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement