Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <vector>
- using namespace std;
- int main() {
- int iter;
- bool q;
- bool s;
- bool pq;
- int oper;
- int value;
- int max;
- int maxindex;
- vector <int> list;
- while (scanf("%d", &iter) != EOF) {
- max = 0;
- maxindex = -1;
- q = true;
- s = true;
- pq = true;
- printf("_____\n");
- printf("%d\n", list.size());
- for (int i = 0; i < iter; i += 1) {
- scanf("%d %d", &oper, &value);
- if (oper == 1) {
- list.push_back(value);
- if (list.size() == 1) {
- max = list.at(0);
- }
- else {
- if (value > max) {
- max = value;
- maxindex = list.size() - 1;
- }
- }
- }
- else {
- if (list.size() == 0) {
- q = false;
- s = false;
- pq = false;
- }
- else {
- if (list.front() != value) {
- q = false;
- }
- if (list.back() != value) {
- s = false;
- }
- if (max != value) {
- pq = false;
- }
- if (max == value) {
- list.erase(list.begin() + maxindex);
- if (list.size() == 0) {
- max = 0;
- maxindex = -1;
- }
- else {
- max = list.at(0);
- maxindex = 0;
- for (int j = 1; j < list.size(); j += 1) {
- if (list.at(j) > max) {
- max = list.at(j);
- maxindex = j;
- }
- }
- }
- }
- else if (list.at(0) == value) {
- list.erase(list.begin());
- maxindex -= 1;
- }
- else if (list.at(list.size() - 1) == value) {
- list.pop_back();
- maxindex -= 1;
- }
- }
- }
- }
- list.clear();
- if (q == 0 && s == 0 && pq == 0) {
- printf("impossible\n");
- }
- else if (q == 1 && s == 0 && pq == 0) {
- printf("queue\n");
- }
- else if (q == 0 && s == 1 && pq == 0) {
- printf("stack\n");
- }
- else if (q == 0 && s == 0 && pq == 1) {
- printf("priority queue\n");
- }
- else {
- printf("not sure\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement