其他分享
首页 > 其他分享> > NC14326 Rails

NC14326 Rails

作者:互联网

题目

1.题目大意

2.题目分析

3.题目代码

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    while(cin >> n){
        if(!n) break;
        while(true) {
            int a[n+1];
            cin >> a[1];
            if(!a[1]) {
                cout << endl;
                break;
            }
            for(int i=2;i<=n;i++) cin >> a[i];
            stack<int> s;
            int tmp = 1;
            for(int i=1;i<=n;i++) {
                if(!s.empty()&&s.top()==a[i]) s.pop();
                else {
                    while(a[i]!=tmp) {
                        s.push(tmp++);
                        if(tmp>n+1)
                            break;
                    }
                    tmp++;
                }            
            } 
            if(!s.empty()) cout << "No" << endl;
            else cout << "Yes" << endl;    
        }
    }
}

标签:题目,cout,int,Rails,C++,NC14326
来源: https://www.cnblogs.com/zhangyi101/p/16618525.html