求助QAQ
查看原帖
求助QAQ
112799
Perseis楼主2021/9/17 16:25

RT,想问问各位大佬为什么会RE哇QAQ

#include<bits/stdc++.h>
using namespace std;
queue<int>q;
stack<int>s;
priority_queue<int,vector<int>,less<int> >pq;
int n,k,x,a,b,c,m,y,z,d; 
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		a=1,b=1,c=1;
		while(n--)
		{
			scanf("%d%d",&k,&m);
			if(k==1)
			{
				q.push(m);
				s.push(m);
				pq.push(m);	
			}
			if(k==2)
			{
				//printf("q %d s %d pq %d\n",x,y,z);
				if(a)
				{
					x = q.front();
					if(x!=m) a =0;
				}
				if(b)
				{
					y = s.top();
					if(y!=m) b=0;
				}
				if(c)
				{
					z = pq.top();
					if(z!=m) c=0;
				}
				q.pop();
				s.pop();
				pq.pop();
			}
		}
		d = a+b+c;
		if(!d) printf("impossible\n");
		else if(d>1) printf("not sure\n");
		else
		{
			if(a) printf("queue\n");
			if(b) printf("stack\n");
			if(c) printf("priority queue\n");
		}
		while(!q.empty()) q.pop();
		while(!s.empty()) s.pop();
		while(!pq.empty()) pq.pop();
	}
	return 0;
}

谢谢各位解答的大佬QAQ

2021/9/17 16:25
加载中...