2 6 Add 18353364208 Add 18353365550 Add 18353365558 Add 18353365559 Del Out
18353365558 18353364208
用一个栈和一个对列模拟一下就好了。。数据好弱
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include <deque> #include <stack> #include <map> #include <set> #define ll long long #define maxn 1010 #define pp pair<int,int> #define INF 0x3f3f3f3f #define max(x,y) ( ((x) > (y)) ? (x) : (y) ) #define min(x,y) ( ((x) > (y)) ? (y) : (x) ) using namespace std; int n,m,top,st,en; char s[300010][33],q[300010][33]; int main() { while(~scanf("%d%d",&n,&m)) { int ok=1; top=0;st=0;en=0; char op[4],x[33]; for(int i=1;i<=m;i++) { scanf("%s",op); if(!strcmp(op,"Add")) { scanf("%s",x); if(top<n) strcpy(s[top++],x); else strcpy(q[en++],x); } else if(!strcmp(op,"Del")) { if(top) { top--; if(st<en) strcpy(s[top++],q[st++]); } else ok=0; } else if(!strcmp(op,"Out")) { if(st<en) st++; else ok=0; } } if(ok) { for(int i=top-1;i>=0;i--) printf("%s\n",s[i]); } else puts("Error"); } return 0; }
原文:http://blog.csdn.net/qq_16255321/article/details/41080875