P7912求调
查看原帖
P7912求调
818316
Guozhong_Lin楼主2022/10/21 19:38

输出前两行对了,到后面就不知道怎么回事了

#include<iostream>
using namespace std;
struct x{
	int next;
	bool type;
};
int n,head=1,p,r,sum=0;
x s[200001];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){cin>>s[i].type;s[i].next=i+1;}
	s[n].next=0;
	while(s[head].next){
		p=head;cout<<head;head=s[head].next;
		while(s[p].next){
			r=p;p=s[p].next;
			if(s[r].type!=s[p].type){
				cout<<" "<<p;
				if(head==p)head=s[p].next;
				else s[r].next=s[p].next;
			}
		}
		cout<<endl;
		}
	return 0;
}
2022/10/21 19:38
加载中...