标签:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <stack> #include <queue> using namespace std; struct Node { int x; int t; }; stack<Node*>A,B,C,D; int main() { int N,Case=1; char s[10]; char x; int c; while(scanf("%d",&N)&&N) { printf("Case #%d:\n",Case++); for(int i=1;i<=N;i++) { scanf("%s",s); if(s[1]==‘u‘) { scanf(" %c",&x); scanf("%d",&c); Node* a=new Node(); a->x=c; a->t=i; if(x==‘A‘) A.push(a); else B.push(a); } else if(s[1]==‘o‘) { scanf(" %c",&x); if(x==‘A‘) { if(A.empty()) { printf("%d\n",C.top()->x); C.pop(); } else { printf("%d\n",A.top()->x); A.pop(); } } else { if(B.empty()) { printf("%d\n",C.top()->x); C.pop(); } else { printf("%d\n",B.top()->x); B.pop(); } } } else if(s[1]==‘e‘) { scanf(" %c",&x); scanf(" %c",&x); while(!A.empty()&&!B.empty()) { if(A.top()->t>B.top()->t) { D.push(A.top()); A.pop(); } else { D.push(B.top()); B.pop(); } } while(!A.empty()) { D.push(A.top()); A.pop(); } while(!B.empty()) { D.push(B.top()); B.pop(); } while(!D.empty()) { C.push(D.top()); D.pop(); } } } } return 0; }
2016暑假多校联合---Joint Stacks (STL)
标签:
原文地址:http://www.cnblogs.com/chen9510/p/5754627.html