Rails

http://poj.org/problem?id=1363

View Code
 1 #include<iostream>
 2 #include<stack>
 3 using namespace std ;
 4 int main()
 5 {
 6     int a[1005] ;
 7     int n ;
 8     while(cin>>n,n!=0)
 9     {
10         while(cin>>a[0],a[0])
11         {
12             for(int i=1; i<n; i++)
13             cin>>a[i] ;
14             stack<int>s ;
15             int num = 0 ;
16             for(int i=1; i<=n; i++)
17             {
18                 s.push(i) ;
19                 while(!s.empty()&&s.top()==a[num])
20                 {
21                     s.pop() ;
22                     num++ ;
23                 }
24             }
25             if(s.empty())
26             cout<<"Yes"<<endl ;
27             else
28             cout<<"No"<<endl ;
29         }
30         cout<<endl ;
31     }
32     return 0 ;
33 }
原文地址:https://www.cnblogs.com/yelan/p/2979914.html