Last active
February 18, 2017 09:29
-
-
Save dada8397/b40b8db1cd108ad625cea70a0bd3a2a2 to your computer and use it in GitHub Desktop.
11995 - I Can Guess the Data Structure!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <stack> | |
#include <queue> | |
using namespace std; | |
int main(void) { | |
int n; | |
while(scanf("%d", &n) != EOF) { | |
int cmd, num; | |
bool isStack = true, isQueue = true, isPQueue = true; | |
stack<int> s; | |
queue<int> q; | |
priority_queue<int> pq; | |
while(n--) { | |
scanf("%d %d", &cmd, &num); | |
switch(cmd) { | |
case 1: | |
s.push(num); | |
q.push(num); | |
pq.push(num); | |
break; | |
default: | |
if(s.empty() || s.top() != num) isStack = false; | |
if(q.empty() || q.front() != num) isQueue = false; | |
if(pq.empty() || pq.top() != num) isPQueue = false; | |
if(!s.empty()) s.pop(); | |
if(!q.empty()) q.pop(); | |
if(!pq.empty()) pq.pop(); | |
break; | |
} | |
} | |
if(isStack + isQueue + isPQueue > 1) | |
printf("not sure\n"); | |
else if(isStack) printf("stack\n"); | |
else if(isQueue) printf("queue\n"); | |
else if(isPQueue) printf("priority queue\n"); | |
else printf("impossible\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment