Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 10. Key Revolver.cpp
- //
- #include <iostream>
- #include <queue>
- #include <stack>
- #include <string>
- #include <sstream> // std::istringstream
- using namespace std;
- queue<int> readInputQueue()
- {
- queue<int> words;
- string input;
- getline(cin, input);
- istringstream istr(input);
- string word;
- while (istr >> word)
- {
- words.push(stoi(word));
- }
- return words;
- }
- stack<int> readInputStack()
- {
- stack<int> words;
- string input;
- getline(cin, input);
- istringstream istr(input);
- string word;
- while (istr >> word)
- {
- words.push(stoi(word));
- }
- return words;
- }
- int main()
- {
- int priceBuller;
- int sizeBarrel;
- int intelligence;
- cin >> priceBuller; cin.ignore();
- cin >> sizeBarrel; cin.ignore();
- stack<int> bullets = readInputStack();
- queue<int> locks = readInputQueue();
- cin >> intelligence;
- int bullet, lock, currentBarel = sizeBarrel, countBullets = 0;
- while (true)
- {
- bullet = bullets.top();
- bullets.pop(); currentBarel--;
- lock = locks.front();
- countBullets++;
- if (bullet > lock)
- {
- cout << "Ping" << endl;
- }
- else
- {
- cout << "Bang" << endl;
- locks.pop();
- if (locks.empty())
- {
- if (currentBarel == 0)
- {
- cout << "Reloading" << endl;
- currentBarel = sizeBarrel;
- }
- cout << bullets.size() << " bullets left. Erned $" <<
- intelligence - countBullets * priceBuller << endl;
- return 0;
- }
- }
- if (currentBarel == 0)
- {
- cout << "Reloading" << endl;
- currentBarel = sizeBarrel;
- }
- if (bullets.empty())
- {
- cout << "Could't get through. Locks left: " << locks.size() << endl;
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment