Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KT-Yeh/9288727 to your computer and use it in GitHub Desktop.
Save KT-Yeh/9288727 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <stack>
#include <queue>
using namespace std;
int main()
{
// freopen("input.txt","rt",stdin);
int N, Command, num;
while (scanf("%d", &N) != EOF) {
stack<int> S;
queue<int> Q;
priority_queue<int> PQ;
bool isStack = 1, isQueue = 1, isPriQueue = 1;
while (N--) {
scanf("%d%d", &Command, &num);
if (Command == 1) {
S.push(num);
Q.push(num);
PQ.push(num);
}
else {
if (S.empty() || S.top() != num) isStack = 0;
if (Q.empty() || Q.front() != num) isQueue = 0;
if (PQ.empty() || PQ.top() != num) isPriQueue = 0;
if (!S.empty()) S.pop();
if (!Q.empty()) Q.pop();
if (!PQ.empty()) PQ.pop();
}
}
if (isStack + isQueue + isPriQueue > 1)
puts("not sure");
else if (isStack) puts("stack");
else if (isQueue) puts("queue");
else if (isPriQueue) puts("priority queue");
else puts("impossible");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment