求交,谢谢(玄关)
查看原帖
求交,谢谢(玄关)
817984
wzq100205楼主2025/8/5 00:48

代码:


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e3+10;
stack<int>t;
int main(){
	int N;
	while(1){
		scanf("%d",&N);
		if(N==0)return 0;
		int x=-1,flag=0;
		while(1){
			while(!t.empty())t.pop();
			int now=0;
			for(int i=0;i<N;i++){
				scanf("%d",&x);
				if(x==0)break;
				if(x>now){
					for(int j=now+1;j<x;j++){
						t.push(j);
					}
					now=x;
				}else{
					if(t.empty()||t.top()!=x){
						cout<<"No"<<endl;
						flag=1;
						break;
					}else{
						t.pop();
					}
				}
			}
			if(x==0)break;
			if(flag==1)continue;
			cout<<"Yes"<<endl;
		}
		cout<<endl;
	}
	return 0;
}

2025/8/5 00:48
加载中...