No
推荐指数:※※
来源:http://ac.jobdu.com/problem.php?pid=1366
这道题也是模拟stack的操作,和http://blog.csdn.net/zhu_liangwei/article/details/9699695这道题思想类似。
#include<stdio.h> #include<stdlib.h> #include<iostream> using namespace std; bool check_stack(int *s,int *pops,int n) { int top,pop_now,curr; top=0,pop_now=1,curr=0;//top: stack top now;pop_now:now to handle;curr:first wait to push int *st= new int[n+1]; while(pop_now<=n&&curr<=n){ if(0==top||st[top]!=pops[pop_now]){ if(top+1>n) return false; else st[++top]=s[++curr]; } else //if equal, emulate operate of pop { top--; pop_now++; } } if(top>0) return false; return true; } int main() { int n,i; while(scanf("%d",&n)!=EOF){ int *st=new int[n+1]; int *arr=new int [n+1]; for(i=1;i<=n;i++) scanf("%d",&st[i]); for(i=1;i<=n;i++) scanf("%d",&arr[i]); if(check_stack(st,arr,n)==false) printf("No\n"); else printf("Yes\n"); } return 0; }