UVa 514 - Rails

是道例题,没错就是道例题。书上有代码,就是有代码。有代码的题应该不写博客的,可是代码不对,不对!!!!


#include<iostream>
#include<stack>
using namespace std;
const int maxn=1000+10;
int n,target[maxn];
int main(){
    while(cin>>n&&n){
        while(cin>>target[1]&&target[1]){
            stack<int>s;
            int A=1,B=1;
            for(int i=2;i<=n;i++)
                cin>>target[i];
            int ok=1;
            while(B<=n){
                if(A==target[B]){
                    A++;
                    B++;
                }
                else if(!s.empty()&&s.top()==target[B]){
                    s.pop();
                    B++;
                }
                else if(A<=n) s.push(A++);
                else{
                    ok=0;
                    break;
                }
            }
            if(ok) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
        
        cout<<endl;
    }
    return 0;
}


你可能感兴趣的:(uva)