Advertisement
Spocoman

Cinema Voucher

Sep 16th, 2023
1,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     int voucherAmount, ticketPurchased = 0, otherPurchased = 0;
  9.     cin >> voucherAmount;
  10.     cin.ignore();
  11.  
  12.     string command;
  13.  
  14.     while (true) {
  15.         getline(cin, command);
  16.  
  17.         if (command == "End") {
  18.             break;
  19.         }
  20.  
  21.         voucherAmount -= command[0] + (command.length() > 8 ? command[1] : 0);
  22.  
  23.         if (voucherAmount < 0) {
  24.             break;
  25.         }
  26.        
  27.         command.length() > 8 ? ticketPurchased++ : otherPurchased++;
  28.     }
  29.  
  30.     cout << ticketPurchased << endl << otherPurchased << endl;
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement