Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <deque>
- #include <iostream>
- #include <vector>
- using std::cin;
- using std::cout;
- using std::deque;
- using std::max;
- using std::min;
- using std::string;
- using std::vector;
- int main() {
- std::ios::sync_with_stdio(false);
- std::cin.tie(0);
- std::cout.tie(0);
- deque<int> qa;
- deque<int> qb;
- int qur;
- cin >> qur;
- int cnt1 = 0;
- int cnt2 = 0;
- int num = 0;
- for (int step = 0; step < qur; ++step) {
- char type;
- cin >> type;
- int nmb;
- if (type != '-') {
- cin >> nmb;
- }
- if (type == '+') {
- if (cnt1 == 0) {
- qa.push_back(nmb);
- cnt1++;
- continue;
- }
- if (cnt1 == num) {
- qa.push_back(qb.front());
- qb.pop_front();
- qb.push_back(nmb);
- cnt1++;
- } else {
- num++;
- cnt2++;
- qb.push_back(nmb);
- }
- } else if (type == '*') {
- if (cnt1 == num) {
- qa.push_back(nmb);
- cnt1++;
- } else {
- cnt2++;
- num++;
- qb.push_front(nmb);
- }
- } else {
- int res = qa.front();
- qa.pop_front();
- cout << res << "\n";
- if (cnt1 == num + 1) {
- cnt1--;
- } else {
- int go = qb.front();
- qa.push_back(go);
- qb.pop_front();
- num--;
- cnt2--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement