标签:
#include <iostream> #include <stack> #include <queue> #include <cstring> #include <cstdio> using namespace std; stack<int> sta; queue<int> que; int main() { int c,n; char data[5]; cin>>c; while(c--) { cin>>n>>data; getchar(); if(strcmp(data,"FIFO")==0) { for(int i=0;i<n;i++) { char ch[20]; int k=0; gets(ch); if(strcmp(ch,"OUT")==0) { if(que.empty()==true) cout<<"None"<<endl; else { k=que.front(); cout<<k<<endl; que.pop(); } } else { for(int i=3;i<strlen(ch);i++) k=k*10+ch[i]-‘0‘; que.push(k); } } } else { for(int i=0;i<n;i++) { char ch[20]; int k=0; gets(ch); if(strcmp(ch,"OUT")==0) { if(sta.empty()==true) cout<<"None"<<endl; else { k=sta.top(); cout<<k<<endl; sta.pop(); } } else { for(int i=3;i<strlen(ch);i++) k=k*10+ch[i]-‘0‘; sta.push(k); } } } while(!sta.empty()) sta.pop(); while(!que.empty()) que.pop(); } return 0; }
hdu 1702 ACboy needs your help again!
标签:
原文地址:http://www.cnblogs.com/nefu929831238/p/5486454.html