天生我材必有难,千金散尽还债来 • 5个月前
#include<iostream>
using namespace std;
int a[100000],b[100000],d=0,f=0;
typedef struct tree {
int data;
tree *l,*r;
} treem,*treel;
void shu1(treel &diyi) {
diyi=new tree;
int x=0;
cin>>x;
if(x==-1) {
diyi=NULL;
return;
} else {
diyi->data=x;
shu1(diyi->l);
shu1(diyi->r);
}
}
void shu2(treel &dier) {
dier=new tree;
int x=0;
cin>>x;
if(x==-1) {
dier=NULL;
return;
} else {
dier->data=x;
shu2(dier->l);
shu2(dier->r);
}
}
void chu1(treel &diyi) {
if(diyi!=NULL) {
if(diyi->l==NULL&&diyi->r==NULL) {
a[d]=diyi->data;
d++;
}
chu1(diyi->l);
chu1(diyi->r);
}
}
void chu2(treel &dier) {
if(dier!=NULL) {
if(dier->l==NULL&&dier->r==NULL) {
b[f]=dier->data;
f++;
}
chu2(dier->l);
chu2(dier->r);
}
}
int main() {
treel diyi,dier;
shu1(diyi);
shu2(dier);
chu1(diyi);
chu2(dier);
if(d!=f){
cout<<"no";
return 0;
}
for(int k=0;k<d;k++){
if(a[k]!=b[k]){
cout<<"no";
return 0;
}
}
cout<<"yes";
return 0;
}
评论:
请先登录,才能进行评论