Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int main() {
- int neededBeers;
- cin >> neededBeers;
- cin.ignore();
- long deliveredBeers = 0;
- string command;
- getline(cin, command);
- while (command != "Exam Over") {
- int index = command.find(' ');
- long amount = stoi(command.substr(0, index));
- string type = command.substr(index + 1, command.length() - index);
- if (type == "sixpacks") {
- amount *= 6;
- }
- else if (type == "cases") {
- amount *= 24;
- }
- deliveredBeers += amount;
- getline(cin, command);
- }
- deliveredBeers -= deliveredBeers / 100;
- long diff = abs(neededBeers - deliveredBeers);
- long cases = diff / 24;
- long sixpacks = diff % 24 / 6;
- long beers = diff % 6;
- if (deliveredBeers >= neededBeers) {
- printf("Cheers! Beer left: %i cases, %i sixpacks and %i beers.", cases, sixpacks, beers);
- }
- else {
- printf("Not enough beer. Beer needed: %i cases, %i sixpacks and %i beers.", cases, sixpacks, beers);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement