标签:style blog color os io 数据 for div
STL数据结构(queue,stack,priority queue)的基本操作;
1 #include <iostream> 2 #include <cstring> 3 #include <queue> 4 #include <stack> 5 using namespace std; 6 7 8 9 int main (){ 10 int n; 11 int x[1005][2]; 12 while (cin>>n){ 13 for (int i=0;i<n;i++){ 14 cin>>x[i][1]>>x[i][0]; 15 } 16 queue<int> q1; 17 stack<int> q2; 18 priority_queue<int> q3; 19 int flag[5]; 20 for (int i=0;i<5;i++) flag[i]=1; 21 for (int i=0;i<n;i++){ 22 if (x[i][1]==1){ 23 q1.push (x[i][0]); 24 q2.push (x[i][0]); 25 q3.push (x[i][0]); 26 } 27 else { 28 if (flag[1]&&(q1.empty()||q1.front()!=x[i][0])){ 29 flag[1]=0; 30 } 31 if (flag[1]) 32 q1.pop (); 33 if (flag[2]&&(q2.empty()||q2.top()!=x[i][0])){ 34 flag[2]=0; 35 } 36 if (flag[2]) 37 q2.pop (); 38 if (flag[3]&&(q3.empty()||q3.top()!=x[i][0])){ 39 flag[3]=0; 40 } 41 if (flag[3]) 42 q3.pop (); 43 44 45 } 46 } 47 int temp=0; 48 for (int i=1;i<=3;i++) 49 temp+=flag[i]; 50 if (temp==0) 51 cout<<"impossible"<<endl; 52 else if (temp>=2) 53 cout<<"not sure"<<endl; 54 else if (temp==1){ 55 if (flag[1]) 56 cout<<"queue"<<endl; 57 else if (flag[2]) 58 cout<<"stack"<<endl; 59 else 60 cout<<"priority queue"<<endl; 61 } 62 63 } 64 return 0; 65 }
UVA 11995 I Can Guess the Data Structure!,布布扣,bubuko.com
UVA 11995 I Can Guess the Data Structure!
标签:style blog color os io 数据 for div
原文地址:http://www.cnblogs.com/gfc-g/p/3889371.html