题解:把原本结构体的左右子树的类型定义成 int 型,用来存放这个结点的左右子树的编号,分别建造两棵二叉树,按个比较,如果在第二棵树中没有找到,那么就不用在判断了。

#include <bits/stdc++.h>

using namespace std;

struct node
{
char data;
int l,r;
};
struct node t1[20],t2[20];
void build(struct node *t, int n)
{
for(int i = 0; i < n; i ++)
{
char s[55];
scanf("%s", s);
t[i].data = s[0];
scanf("%s", s);
if(s[0] == '-') t[i].l = 100;
else t[i].l = s[0] - '0';
scanf("%s", s);
if(s[0] == '-') t[i].r = 100;
else t[i].r = s[0] - '0';
}
}
int ok(int i, int j)
{
if(t1[t1[i].l].data == t2[t2[j].l].data && t1[t1[i].r].data == t2[t2[j].r].data)
return 1;
else if(t1[t1[i].r].data == t2[t2[j].l].data && t1[t1[i].l].data == t2[t2[j].r].data)
return 1;
else return 0;
}
int main()
{
int n,m;
while(~scanf("%d",&n))
{
build(t1,n);
scanf("%d",&m);
build(t2,m);
int f = 0,i,j;
for(i = 0; i < n; i ++)
{
for( j = 0; j < m; j ++)
{
if(t1[i].data == t2[j].data)
{
if(ok(i,j)==0){
f = 1;
break;
}
else break;
}
}
if(f)break;
if(j >= m){f = 1;break;}
}
if(f)printf("No\n");
else printf("Yes\n");
}
return 0;
}

最新文章

  1. 测试--jmeter的使用
  2. bootstrap-导航、选项卡
  3. try catch语句在VC下的处理
  4. 2014 百度之星题解 1002 - Disk Schedule
  5. Reactor模型
  6. 我的Hook学习笔记
  7. LVS集群的体系结构
  8. 【Android Developers Training】 51. 序言:打印内容
  9. 51nod 1020 逆序排列 DP
  10. Jmeter MD5插件
  11. ATM+购物商城完整版
  12. 配置ubuntu
  13. OPNET仿真软件资料合集
  14. 从Spring到SpringBoot构建WEB MVC核心配置详解
  15. C#Delegate.Invoke、Delegate.BeginInvoke And Control.Invoke、Control.BeginInvoke
  16. 逆变(contravariant)与协变(covariant)
  17. HBase的简单java操作
  18. 配置python的豆瓣source
  19. vue发布后的一些问题
  20. Android学习笔记_46_Android的intent之间Object、List、List&lt;Object&gt;和全局变量数据的传递(Parcelable Serializable)

热门文章

  1. javascript语法糖
  2. CentOS7安装firewall防火墙
  3. typeAliasesPackage 属性的作用
  4. FLV 数据封装格式
  5. extjs layout 最灵活的页面布局样式
  6. FICO-财务凭证验证及替代
  7. ORA-01790 错误处理 SQL同一数据库中,两个查询结果数据类型不同时的union all 合
  8. 网络基础 InetAddress
  9. [476] Database Mail is not enabled for agent notifications. Cannot send e-mail to
  10. DNS服务——域名解析容错