13 solutions

  • 0
    @ 2022-3-24 11:36:24

    不才,斗胆发一下自己的写法....可能很菜0.0

    #include<bits/stdc++.h>
    #define MAX 1000
    using namespace std;
    
    int  B[MAX];
    int main(){
    stack<int>   c;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
    cin>>B[i];
    }
    int j=1;
    int i=1;
    do{
    if(c.empty()==0){
    if(c.top()==B[j]){
    c.pop();
    j++;
    continue;
    }
    }
    if(i<=n){
    c.push(i);
    i++;
    continue;
    }
    if(!c.empty()&&i>n){
    cout<<"NO"<<endl;
    break;
    }
    }while(j<=n);
    if(j>n)   cout<<"YES"<<endl;
    return 0;
    }
    

    Information

    ID
    291
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    6
    Tags
    # Submissions
    139
    Accepted
    44
    Uploaded By