求教40分
查看原帖
求教40分
238203
跟你沟通楼主2020/10/29 19:58
#include<bits/stdc++.h>
using namespace std;
struct NODE
{
	int num,l,r,father;
}tree[30];
int n;
void print(int now)
{
	if(tree[now].num=='\0')return;
	printf("%c",'a'+tree[now].num-1);
	print(tree[now].l);
	print(tree[now].r);
}
int main()
{
	cin>>n;
	char a,b,c;
	for(int i=1;i<=n;++i)
	{
		tree[i].father=i;
		cin>>a>>b>>c;
		getchar();
		tree[a-'a'+1].num=a-'a'+1;
		if(b!='*')
		{	
			tree[a-'a'+1].l=b-'a'+1;
			tree[b-'a'+1].father=a-'a'+1;
		}
		if(c!='*')
		{
			tree[a-'a'+1].r=c-'a'+1;
			tree[c-'a'+1].father=a-'a'+1;
		}
	}
	int f=1;
	while(tree[f].father!=f)f=tree[f].father;
	print(f);
}
2020/10/29 19:58
加载中...