SPOJ Street Parade solution

Правка en2, от vee_sharp, 2015-12-15 16:36:09

I am trying to solve SPOJ street parade. But i dont know what is wrong in the following code:

#include<iostream>
#include<algorithm>
#include<stack>
#include<cstdio>
using namespace std;
int main(){
	int n,ne,last;
	cin>>n;
	while(n!=0){
		int ar[n];
		last=0;
        stack <int> s;
        for(int i=0;i<n;i++) 
            cin>>ar[i];
		for(int i=0;i<n;i++){
			if(s.top()==(last+1)){
				s.pop();
				last++;
			}
			else if(ar[i]==(last+1))
				last++;
			else if(!s.empty() && s.top()<ar[i]){
				cout<<"no"<<endl;
				continue;
			}
			else
				s.push(ar[i]);
		}
		cout<<"yes"<<endl;
		cin>>n;
	}
	return 0;
}

Теги stack, spoj, c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский vee_sharp 2015-12-15 16:36:09 5 Tiny change: 'ng code:\n[cut]\n~~~~~\n#' -
en1 Английский vee_sharp 2015-12-15 16:35:38 706 Initial revision (published)