TOJ1036.Rails STL栈

 1 /*
 2    功能Function Description:    STL-栈 TOJ-1036.Rails   zoj-1259  poj-1363
 3    开发环境Environment:          DEV C++ 4.9.9.1
 4    技术特点Technique:
 5    版本Version:
 6    作者Author:                   可笑痴狂
 7    日期Date:                      20120801
 8    备注Notes:
 9    题目来源:
10         http://acm.tju.edu.cn/toj/showp1036.html
11    题意;进站顺序一定,判断是否能按给出的顺序出站
12 */
13 
14 #include<cstdio>
15 #include<iostream>
16 #include<stack>
17 using namespace std;
18 
19 int main()
20 {
21     int n,i,k;
22     int a[1010];
23     stack<int> s;
24     while(scanf("%d",&n),n)
25     {
26         while(scanf("%d",&a[1]))
27         {
28             if(a[1]==0)
29             {
30                 printf("\n");
31                 break;
32             }
33             while(!s.empty())       //初始化清空栈
34                 s.pop();
35             k=1;
36             for(i=2;i<=n;++i)
37                 scanf("%d",&a[i]);
38             for(i=1;i<=n;++i)
39             {
40                 s.push(i);
41                 if(i==a[k])
42                 {
43                     while(!s.empty()&&s.top()==a[k])
44                     {
45                         s.pop();
46                         ++k;
47                     }
48                 }
49             }
50             if(s.empty())
51                 printf("Yes\n");
52             else
53                 printf("No\n");
54         }
55     }
56     return 0;
57 }
功不成,身已退
原文地址:https://www.cnblogs.com/dongsheng/p/2618328.html