UVA514 交不上去(waiting)
查看原帖
UVA514 交不上去(waiting)
450893
yangyuanxi44楼主2021/7/30 17:24

UVA514 我交不上去,。。,连交4次555, 谢谢大佬求助

提交记录

代码:

#include<bits/stdc++.h>
using namespace std;
int n;
stack<int>z; 
int a[1005],b[1005];

int main(){
	int pd=1;
	while(1){
		
		cin>>n;
		if(n==0) return 0;
	
		while(1){
			pd=1;
			for(int i=1 ; i<=n ; i++){
				a[i]=i;
				cin>>b[i];
				if(b[i]==0&&i==1){
					pd=0;
					cout<<endl;
					break;
				}
			}
			//cout<<"!";
			if(pd==0) break;
			int t=1;
			//cout<<"!";
			for(int i=1 ; i<=n ; i++){
				z.push(a[i]);
				while(z.top()==b[t]){
					z.pop();
					t++;
					if(z.empty()) break;
				}
			}
			if(z.empty()) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
			while(!z.empty()) z.pop();
		}
	}
	}
 

谢谢大佬

2021/7/30 17:24
加载中...