Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- const int BOTTLED_DETERGENT_IN_MILILITERS = 750;
- int detergentCount, counter = 1, dishes = 0, pots = 0;
- cin >> detergentCount;
- int detergentQuantity = detergentCount * BOTTLED_DETERGENT_IN_MILILITERS;
- string command;
- while (true) {
- cin >> command;
- if (command == "End") {
- cout << "Detergent was enough!\n"
- << dishes << " dishes and " << pots << " pots were washed.\n"
- << "Leftover detergent " << detergentQuantity << " ml.\n";
- break;
- }
- int detergentRefillInMililiters = stoi(command);
- if (counter % 3 != 0) {
- dishes += detergentRefillInMililiters;
- detergentQuantity -= detergentRefillInMililiters * 5;
- }
- else {
- pots += detergentRefillInMililiters;
- detergentQuantity -= detergentRefillInMililiters * 15;
- }
- if (detergentQuantity < 0) {
- cout << "Not enough detergent, " << abs(detergentQuantity) << " ml. more necessary!\n";
- break;
- }
- counter++;
- }
- return 0;
- }
- РЕШЕНИЕ С FOR:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- const int BOTTLED_DETERGENT_IN_MILILITERS = 750;
- int detergentCount, dishes = 0, pots = 0;
- cin >> detergentCount;
- int detergentQuantity = detergentCount * BOTTLED_DETERGENT_IN_MILILITERS;
- string command;
- for (int counter = 1; counter < 2147483647; counter++) { // INT_MAX = 2147483647
- cin >> command;
- if (command == "End") {
- cout << "Detergent was enough!\n"
- << dishes << " dishes and " << pots << " pots were washed.\n"
- << "Leftover detergent " << detergentQuantity << " ml.\n";
- break;
- }
- int detergentRefillInMililiters = stoi(command);
- if (counter % 3 != 0) {
- dishes += detergentRefillInMililiters;
- detergentQuantity -= detergentRefillInMililiters * 5;
- }
- else {
- pots += detergentRefillInMililiters;
- detergentQuantity -= detergentRefillInMililiters * 15;
- }
- if (detergentQuantity < 0) {
- cout << "Not enough detergent, " << abs(detergentQuantity) << " ml. more necessary!\n";
- break;
- }
- }
- return 0;
- }
- РЕШЕНИЕ С FOR И ТЕРНАРЕН ОПЕРАТОР:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- const int BOTTLED_DETERGENT_IN_MILILITERS = 750;
- int detergentCount, dishes = 0, pots = 0;
- cin >> detergentCount;
- int detergentQuantity = detergentCount * BOTTLED_DETERGENT_IN_MILILITERS;
- string command;
- cin >> command;
- for (int counter = 1; counter < 2147483647 && command != "End" && detergentQuantity >= 0; counter++) {
- counter % 3 == 1 ? dishes += stoi(command) : pots += stoi(command);
- detergentQuantity -= (counter % 3 == 1 ? 5 : 15) * stoi(command);
- cin >> command;
- }
- command == "End" ?
- cout << "Detergent was enough!\n"
- << dishes << " dishes and " << pots << " pots were washed.\n"
- << "Leftover detergent " << detergentQuantity << " ml.\n" :
- cout << "Not enough detergent, " << abs(detergentQuantity) << " ml. more necessary!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement