Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int x, y;
- cin >> x >> y;
- int cakePieces = x * y;
- string command;
- cin >> command;
- while (cakePieces > 0 && command != "STOP") {
- cakePieces -= stoi(command);
- cin >> command;
- }
- if (cakePieces >= 0){
- cout << cakePieces << " pieces are left.\n";
- }
- else {
- cout << "No more cake left! You need " << abs(cakePieces) << " pieces more.\n";
- }
- return 0;
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int x, y;
- cin >> x >> y;
- int cakePieces = x * y;
- string command;
- cin >> command;
- while (cakePieces > 0 && command != "STOP") {
- cakePieces -= stoi(command);
- cin >> command;
- }
- cakePieces >= 0 ?
- cout << cakePieces << " pieces are left.\n" :
- cout << "No more cake left! You need " << abs(cakePieces) << " pieces more.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement