题目链接:http://poj.org/problem?id=1363
#include <stdio.h> #include <stack> using namespace std; int ans[10000]; ///出栈秩序 int main() { int t; ///有多少车厢 while(scanf("%d",&t),t) { stack<int>s; while(scanf("%d",&ans[0]),ans[0]) { for(int i=1;i<t;i++) scanf("%d",&ans[i]); ///模拟进栈 int k,i; for(i=1,k=0;i<=t;i++) { s.push(i); while(s.top()==ans[k]) { if(!s.empty()) s.pop(); k++; if(s.empty()) break; } } if(k==t) printf("Yes "); else printf("No "); } printf(" "); } return 0; }