Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int width, length;
- cin >> width >> length;
- //брой на парчетата: дълж * шир
- int countPieces = width * length;
- //STOP или броя парчетата < 0
- string command; //STOP ИЛИ ЧИСЛО под формата на текст
- cin >> command;
- //СПИРАМЕ: command == "STOP"
- //Продължаваме: command != "STOP"
- while (command != "STOP") {
- //брой парчета -> число -> "3"
- int takenPieces = stoi(command);
- countPieces -= takenPieces;
- if (countPieces < 0) {
- //-1
- cout << "No more cake left! You need " << abs(countPieces) << " pieces more." << endl;
- break;
- }
- cin >> command;
- }
- if (command == "STOP") {
- cout << countPieces << " pieces are left." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment