uva 11995 I Can Guess the Data Structure!
2017-12-09 22:44
369 查看
题目:I Can Guess the Data Structure!
思路:模拟。
代码:#include<cstdio>
#include<stack>
#include<algorithm>
#include<queue>
#include<deque>
using namespace std;
int n;
int main() {
while(~scanf("%d",&n)) {
bool fstack=1,fque=1,fpri=1;
stack<int> a;
queue<int> b;
priority_queue<int> c;
for(int i=1; i<=n; i++) {
int x,y;
scanf("%d%d",&x,&y);
if(x==1) {
a.push(y);
b.push(y);
c.push(y);
}
if(x==2) {
if(fstack==0||a.empty()||a.top()!=y) fstack=0;
else a.pop();
if(fque==0||b.empty()||b.front()!=y) fque=0;
else b.pop();
if(fpri==0||c.empty()||c.top()!=y) fpri=0;
else c.pop();
}
}
if(fstack==0&&fque==0&&fpri==0) printf("impossible");
else if(fstack==1&&fque==0&&fpri==0) printf(
b109
"stack");
else if(fstack==0&&fque==1&&fpri==0) printf("queue");
else if(fstack==0&&fque==0&&fpri==1) printf("priority queue");
else printf("not sure");
printf("\n");
}
return 0;
}
思路:模拟。
代码:#include<cstdio>
#include<stack>
#include<algorithm>
#include<queue>
#include<deque>
using namespace std;
int n;
int main() {
while(~scanf("%d",&n)) {
bool fstack=1,fque=1,fpri=1;
stack<int> a;
queue<int> b;
priority_queue<int> c;
for(int i=1; i<=n; i++) {
int x,y;
scanf("%d%d",&x,&y);
if(x==1) {
a.push(y);
b.push(y);
c.push(y);
}
if(x==2) {
if(fstack==0||a.empty()||a.top()!=y) fstack=0;
else a.pop();
if(fque==0||b.empty()||b.front()!=y) fque=0;
else b.pop();
if(fpri==0||c.empty()||c.top()!=y) fpri=0;
else c.pop();
}
}
if(fstack==0&&fque==0&&fpri==0) printf("impossible");
else if(fstack==1&&fque==0&&fpri==0) printf(
b109
"stack");
else if(fstack==0&&fque==1&&fpri==0) printf("queue");
else if(fstack==0&&fque==0&&fpri==1) printf("priority queue");
else printf("not sure");
printf("\n");
}
return 0;
}
相关文章推荐
- UVA - 11995 I Can Guess the Data Structure! 猜猜数据结构(STL模拟)
- UVA - 11995 I Can Guess the Data Structure!
- uva——11995——I Can Guess the Data Structure!
- uva 11995——I Can Guess the Data Structure!
- UVA 11995 - I Can Guess the Data Structure! (基本数据结构)
- UVA 11995 I Can Guess the Data Structure!
- uva 11995 - I Can Guess the Data Structure!(STL应用)
- UVa 11995 I Can Guess the Data Structure!
- UVA 11995 I Can Guess the Data Structure!
- uva 11995 I Can Guess the Data Structure! (STL的简单应用)
- uva 11995 I Can Guess the Data Structure!
- (UVA 11995) I Can Guess The Data Structure! --抽象数据结构判断
- uva 11995 I Can Guess the Data Structure!
- UVA 11995 I Can Guess the Data Structure!
- uva 11995 I Can Guess the Data Structure!(数据结构:基础)
- UVa 11995 I Can Guess the Data Structure!
- (UVA - 11995)I Can Guess the Data Structure!
- UVA - 11995 I Can Guess the Data Structure!(模拟)
- uva 11995 I Can Guess the Data Structure!(STL)
- 入门经典训练指南第三章例题1.UVa 11995 I Can Guess the Data Structure!