View Code of Problem 490

#include<iostream>
#include<stack>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=0){
		int a[n];
		while(1){
			cin>>a[0];
			stack<int>x;
			int c=getchar();
			if(c=='\n')
			break;
			
			for(int i=1;i<n;++i)cin>>a[i];
			int p=0,d=1;
			while(d<=n){
				x.push(d++);
					while((!x.empty())&&a[p]==x.top()){
						p++;
						x.pop();	
					}
			}
			if(x.empty())
			cout<<"Yes"<<endl;
			else
			cout<<"No"<<endl;
		}
		cout<<endl;
	}
}

Double click to view unformatted code.


Back to problem 490