HRusev

10. Key Revolver

May 8th, 2023
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | Software | 0 0
  1. // 10. Key Revolver.cpp
  2. //
  3. #include <iostream>
  4. #include <queue>
  5. #include <stack>
  6. #include <string>
  7. #include <sstream>  // std::istringstream
  8.  
  9. using namespace std;
  10.  
  11. queue<int> readInputQueue()
  12. {
  13.     queue<int> words;
  14.     string input;
  15.     getline(cin, input);
  16.     istringstream istr(input);
  17.  
  18.     string word;
  19.     while (istr >> word)  
  20.     {
  21.         words.push(stoi(word));  
  22.     }
  23.  
  24.     return words;
  25. }
  26.  
  27. stack<int> readInputStack()
  28. {
  29.     stack<int> words;
  30.     string input;
  31.     getline(cin, input);
  32.     istringstream istr(input);
  33.  
  34.     string word;
  35.     while (istr >> word)  
  36.     {
  37.         words.push(stoi(word));
  38.     }
  39.  
  40.     return words;
  41. }
  42.  
  43.  
  44. int main()
  45. {
  46.     int priceBuller;
  47.     int sizeBarrel;
  48.     int intelligence;
  49.              
  50.     cin >> priceBuller; cin.ignore();
  51.     cin >> sizeBarrel; cin.ignore();
  52.     stack<int> bullets = readInputStack();
  53.     queue<int> locks = readInputQueue();
  54.     cin >> intelligence;
  55.  
  56.  
  57.     int bullet, lock, currentBarel = sizeBarrel, countBullets = 0;
  58.     while (true)
  59.     {
  60.         bullet = bullets.top();
  61.         bullets.pop(); currentBarel--;
  62.         lock = locks.front();
  63.         countBullets++;
  64.         if (bullet > lock)
  65.         {
  66.             cout << "Ping" << endl;
  67.         }
  68.         else
  69.         {
  70.             cout << "Bang" << endl;
  71.             locks.pop();
  72.            
  73.             if (locks.empty())
  74.             {
  75.                 if (currentBarel == 0)
  76.                 {
  77.                     cout << "Reloading" << endl;
  78.                     currentBarel = sizeBarrel;
  79.                 }
  80.                 cout << bullets.size() << " bullets left. Erned $" <<
  81.                     intelligence - countBullets * priceBuller << endl;
  82.                 return 0;
  83.             }
  84.                
  85.         }
  86.                
  87.         if (currentBarel == 0)
  88.         {
  89.             cout << "Reloading" << endl;
  90.             currentBarel = sizeBarrel;
  91.         }
  92.  
  93.  
  94.         if (bullets.empty())
  95.         {
  96.             cout << "Could't get through. Locks left: " << locks.size() << endl;
  97.             return 0;
  98.         }
  99.  
  100.  
  101.            
  102.            
  103.     }
  104.  
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment