Advertisement
Spocoman

Beer Stock

Oct 11th, 2023
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int neededBeers;
  9.     cin >> neededBeers;
  10.     cin.ignore();
  11.  
  12.     long deliveredBeers = 0;
  13.     string command;
  14.     getline(cin, command);
  15.  
  16.     while (command != "Exam Over") {
  17.         int index = command.find(' ');
  18.         long amount = stoi(command.substr(0, index));
  19.         string type = command.substr(index + 1, command.length() - index);
  20.  
  21.         if (type == "sixpacks") {
  22.             amount *= 6;
  23.         }
  24.         else if (type == "cases") {
  25.             amount *= 24;
  26.         }
  27.         deliveredBeers += amount;
  28.         getline(cin, command);
  29.     }
  30.  
  31.     deliveredBeers -= deliveredBeers / 100;
  32.     long diff = abs(neededBeers - deliveredBeers);
  33.     long cases = diff / 24;
  34.     long sixpacks = diff % 24 / 6;
  35.     long beers = diff % 6;
  36.  
  37.     if (deliveredBeers >= neededBeers) {
  38.         printf("Cheers! Beer left: %i cases, %i sixpacks and %i beers.", cases, sixpacks, beers);
  39.     }
  40.     else {
  41.         printf("Not enough beer. Beer needed: %i cases, %i sixpacks and %i beers.", cases, sixpacks, beers);
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement