#include <iostream> #include <stack> #include <cstdio> #include <cstring> #define MAXN 100 + 10 using namespace std; int a[MAXN],n; int main() { memset(a,66,sizeof(a)); stack<int> s; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int A=1,B=1; bool book=true; while(B<=n) { if(A==a[B]) { A++; B++; } else if(!s.empty() && s.top()==a[B]) { s.pop(); B++; } else if(A<=n) s.push(A++); else { book=false; break; } } if(book) printf("yes"); else printf("no"); //system("pause"); } 铁轨
转载于:https://www.cnblogs.com/jason2003/p/6572026.html
