Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <string>
- using std::cin;
- using std::cout;
- using std::max;
- using std::min;
- using std::string;
- using std::vector;
- using std::queue;
- using std::deque;
- //sample-потестить: как добавлять и удалать из deque mini
- int main() {
- std::ios::sync_with_stdio(false);
- std::cin.tie(0);
- std::cout.tie(0);
- queue<int> qu;
- deque<int> mini;
- int req;
- cin >> req;
- int cnt = 0;
- for (int go = 0; go < req; ++go) {
- string ask;
- cin >> ask;
- if (ask == "enqueue") {
- cnt++;
- int nmb; cin >> nmb;
- qu.push(nmb);
- cout << "ok\n";
- while (!mini.empty() && mini.back() > nmb) {
- mini.pop_back();
- }
- mini.push_back(nmb);
- } else if (ask == "dequeue") {
- if (qu.empty()) {
- cout << "error\n";
- continue;
- }
- cout << qu.front() << "\n";
- if (mini.front() == qu.front()) {
- mini.pop_front();
- }
- qu.pop();
- cnt--;
- } else if (ask == "front") {
- if (qu.empty()) {
- cout << "error\n";
- continue;
- }
- cout << qu.front() << "\n";
- } else if (ask == "size") {
- cout << cnt << "\n";
- } else if (ask == "clear") {
- while (!qu.empty()) {
- qu.pop();
- }
- while (!mini.empty()) {
- mini.pop_back();
- }
- cnt = 0;
- } else if (ask == "min") {
- if (cnt == 0) {
- cout << "error\n";
- continue;
- }
- cout << mini.front() << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement