summaryrefslogtreecommitdiff
path: root/514/test.cpp
blob: 2f79f7283e9c68cc34a7fdea0f451864b186def7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <stack>
using namespace std;

bool in(stack<int> s, int num){
    bool found=false;
    while(!found && s.size()>0){
	found=(s.top()==num);
	s.pop();
    }
    return found;
}

int main(){
    int num;
    cin>>num;
    while(num!=0){
	stack<int> s, orig;
	for(int i=num; i>0; i--)
	    orig.push(i);
	
	bool possible=true, end=false;
	int x;
	for(int i=0; i<num && possible; i++){
	    cin>>x;
	    while(!in(s, x)){
		s.push(orig.top());
		orig.pop();
	    }
	    if(x!=s.top())
		possible=false;

	}
	possible? cout<<"Yes\n" : cout<<"No\n";
	cin>>num;
    }
}