# UVa 514 - Rails ## Online Judge ![](https://i.imgur.com/4dAVb2P.png) ## 解題思路 沒啥好說的,就stack解決。 ## 解題中出現的bug 老問題格式錯誤,一個case處理完後要換行。 ## Code ```cpp= #include <iostream> #include <stack> #include <queue> using namespace std; int arr[1001]; int main() { int N; while(cin >> N && N!=0) { while(cin>>arr[0]&&arr[0]!=0) { for(int i=1;i<N;i++) cin >> arr[i]; stack<int> train; int check = 0; //recode the number of train that can be poppushed for(int i=0;i<N;i++) { train.push(i+1); while(!train.empty() && train.top()==arr[check])//to check stack if it can be popped or not { train.pop(); check++; } } if(train.empty() && check==N ) cout << "Yes\n"; else cout << "No\n"; } cout << endl; } return 0; } ``` ###### tags: `UVA code` `cpp` `林基成-C++` `Awwwolf的刷題之路`