标签:
11995
I Can Guess the Data Structure!
There is a bag-like data structure, supporting two operations:priority queue
/* Author: 2486 Memory: 0 KB Time: 18 MS Language: C++ 4.8.2 Result: Accepted */ //将所有的STL分别进行判断就可以了 #include <iostream> #include <string> #include <algorithm> #include <stack> #include <queue> #include <cstdio> #include <cstring> using namespace std; int n,cmd,dig; bool isstack,isque,isprique; stack<int>sta; queue<int>que; priority_queue<int>prique; int main() { #ifndef ONLINE_JUDGE freopen("D://imput.txt","r",stdin); #endif // ONLINE_JUDGE while(~scanf("%d",&n)) { while(!sta.empty())sta.pop(); while(!que.empty())que.pop(); while(!prique.empty())prique.pop(); isstack=true,isque=true,isprique=true; for(int i=0; i<n; i++) { scanf("%d%d",&cmd,&dig); if(isstack) { if(cmd==1) { sta.push(dig); } else { if(sta.empty()) { isstack=false; while(!sta.empty())sta.pop(); } else { int v=sta.top(); if(v==dig) { sta.pop(); } else { isstack=false; while(!sta.empty())sta.pop(); } } } } if(isque) { if(cmd==1) { que.push(dig); } else { if(que.empty()) { isque=false; while(!que.empty())que.pop(); } else { int v=que.front(); if(v==dig) { que.pop(); } else { isque=false; while(!que.empty())que.pop(); } } } } if (isprique) { if(cmd==1) { prique.push(dig); } else { if(prique.empty()) { isprique=false; while(!prique.empty())prique.pop(); } else { int v=prique.top(); if(v==dig) { prique.pop(); } else { isprique=false; while(!prique.empty())prique.pop(); } } } } } if(isstack+isque+isprique==1) { if(isstack)printf("stack"); else if(isque)printf("queue"); else printf("priority queue"); } else if(isstack+isque+isprique==0) { printf("impossible"); } else { printf("not sure"); } printf("\n"); } return 0; }
UVA 11995 I Can Guess the Data Structure!
标签:
原文地址:http://blog.csdn.net/qq_18661257/article/details/46593113