多校7 HDU5818 Joint Stacks
题意:n次操作。模拟栈的操作,合并的以后,每个栈里的元素以入栈顺序排列
思路:开三个栈,并且用到了merge函数
O(n)的复杂度
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int inf = 0x3f3f3f3f;
const int MOD =;
const int N =;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;}
int n;
int sta[][N],top[];
char op[],s[],s1[];
int x[N];
void fun(){
top[]=top[]=top[]=;
for(int i=;i<n;i++){
scanf("%s%s",op,s);
int a=s[]-'A';
if(op[]=='u'){
scanf("%d",&x[i]);
sta[a][top[a]++]=i;
}
else if(op[]=='o'){
if(!top[a]) a=;
printf("%d\n",x[sta[a][--top[a]]]);
}
else {
scanf("%s",s1);
top[]=merge(sta[],sta[]+top[],sta[],sta[]+top[],sta[]+top[])-sta[];
top[]=top[]=;
}
}
}
int main(){
int cas=;
while(~scanf("%d",&n),n){
printf("Case #%d:\n", cas++);
fun();
}
return ;
}