Advertisement
Spocoman

01. Counter-Strike

Nov 8th, 2023
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int energy, count = 0, battleIndex;
  8.     cin >> energy;
  9.     cin.ignore();
  10.  
  11.     string command;
  12.     getline(cin, command);
  13.  
  14.     while (command != "End of battle") {
  15.         battleIndex = stoi(command);
  16.         if (energy < battleIndex) {
  17.             break;
  18.         }
  19.         count++;
  20.         if (count % 3 == 0) {
  21.             energy += count;
  22.         }
  23.         energy -= battleIndex;
  24.         getline(cin, command);
  25.     }
  26.  
  27.     if (command == "End of battle") {
  28.         cout << "Won battles: " << count << ". Energy left: " << energy << endl;
  29.     }
  30.     else {
  31.         cout << "Not enough energy! Game ends with " << count << " won battles and " << energy << " energy\n";
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement