desislava_topuzakova

06. Cake

Feb 7th, 2021
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int width, length;
  8.     cin >> width >> length;
  9.     //брой на парчетата: дълж * шир
  10.     int countPieces = width * length;
  11.     //STOP или броя парчетата < 0
  12.     string command; //STOP ИЛИ ЧИСЛО под формата на текст
  13.     cin >> command;
  14.  
  15.     //СПИРАМЕ: command == "STOP"
  16.     //Продължаваме: command != "STOP"
  17.     while (command != "STOP") {
  18.         //брой парчета -> число -> "3"
  19.         int takenPieces = stoi(command);
  20.         countPieces -= takenPieces;
  21.         if (countPieces < 0) {
  22.             //-1
  23.             cout << "No more cake left! You need " << abs(countPieces) << " pieces more." << endl;
  24.             break;
  25.         }
  26.  
  27.         cin >> command;
  28.     }
  29.  
  30.     if (command == "STOP") {
  31.         cout << countPieces << " pieces are left." << endl;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment