30分,样例过了,求大佬帮帮
查看原帖
30分,样例过了,求大佬帮帮
466312
无奈之白楼主2021/11/5 17:32

代码在这

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
void postorder(int root);
#define MAXN 100000
struct tnode
{
	char data;
	int lc,rc;
} t[MAXN];
int main()
{
	char str[2000];
	int N,len,i,j;
	cin>>N>>str+1; 
	len=strlen(str)-1;
	for (i=1;i<=len;i++)
	{
		if (str[i]=='0') t[i].data='B';
		else t[i].data='I';
		t[i].lc=t[i].rc=0;
	}
	for(i=1,j=len+1;j<=2*len-1;i+=2,j++)
	{
		t[j].lc=i;
		t[j].rc=i+1;
		if (t[i].data==t[i+1].data) t[j].data=t[i].data;
		else t[j].data='F';
	}
	postorder(2*len-1);
	return 0;
} 
void postorder(int root)
{
	if (root)
	{
		postorder(t[root].lc);
		postorder(t[root].rc);
		cout<<t[root].data;
	}
}
2021/11/5 17:32
加载中...