luoguUVA11995 I Can Guess the Data Structure

版权声明:本文为博主原创文章,未经博主允许不得转载,不得用于商业用途。 https://blog.csdn.net/WDAJSNHC/article/details/82263319

luoguUVA11995 I Can Guess the Data Structure

时空限制    1000ms/128MB

题目描述

输入输出格式

输入格式:

输出格式:

输入输出样例

输入样例#1:

6
1 1
1 2
1 3
2 1
2 2
2 3
6
1 1
1 2
1 3
2 3
2 2
2 1
2
1 1
2 2
4
1 2
1 1
2 1
2 2
7
1 2
1 5
1 1
1 3
2 5
1 4
2 4

输出样例#1:

queue
not sure
impossible
stack
priority queue

代码

#include<iostream>
#include<stack>
#include<queue>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n;
	bool fs,fq,fpq;
	while (cin>>n){
		stack<int> s;
		queue<int> q;
		priority_queue<int> pq;
		fs = fq = fpq = true;
		for (int i=1,x,y; i<=n; i++){
			cin>>x>>y;
			if (x==1){	//操作1
				s.push(y);  q.push(y); pq.push(y);
			}
			else {	//操作2
				if (fs)	//栈
					if (!s.empty() && s.top()==y) s.pop();
					else fs=false;
				if (fq)	//队列
					if (!q.empty() && q.front()==y) q.pop();
					else fq=false;
				if (fpq)	//优先队列
					if (!pq.empty() && pq.top()==y) pq.pop();
					else fpq=false;
			}
		}
		if (!fs && !fq && !fpq) cout<<"impossible\n";
		else if (fs && !fq && !fpq) cout<<"stack\n";
		else if (!fs && fq && !fpq) cout<<"queue\n";
		else if (!fs && !fq && fpq) cout<<"priority queue\n";
		else cout<<"not sure\n";
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/WDAJSNHC/article/details/82263319