博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PTA树的同构c++版——山东科技大学
阅读量:4032 次
发布时间:2019-05-24

本文共 1590 字,大约阅读时间需要 5 分钟。

在这里插入图片描述

在这里插入图片描述

#include
using namespace std;struct A{
char ch; int l,r; bool root;}a[15],b[15];int n1,n2;char ch;char l,r;bool judge(int root1,int root2){
if(root1==-1&&root2==-1) return true; if((root1==-1&&root2!=-1)||(root1!=-1&&root2==-1)) return false; if(a[root1].ch!=b[root2].ch) return false; if(judge(a[root1].l,b[root2].l)&&judge(a[root1].r,b[root2].r)) return true; if(judge(a[root1].l,b[root2].r)&&judge(a[root1].r,b[root2].l)) return true; return false;}void print(int r){
if(r==-1) return; cout<
<<' '; print(b[r].l); print(b[r].r);}void build(){
cin>>n1; for(int i=0;i
>ch>>l>>r; a[i].ch=ch; if(l=='-') a[i].l=-1; else {
a[i].l=l-'0'; a[a[i].l].root=true;//节点不是树根 //正常来说应该是false,但因为初始化是true //所以用true来否定,下同。 } if(r=='-') a[i].r=-1; else {
a[i].r=r-'0'; a[a[i].r].root=true; } } cin>>n2; for(int i=0;i
>ch>>l>>r; b[i].ch=ch; if(l=='-') b[i].l=-1; else {
b[i].l=l-'0'; b[b[i].l].root=true; } if(r=='-') b[i].r=-1; else {
b[i].r=r-'0'; b[b[i].r].root=true; } }}int main(){
//freopen("in.txt","r",stdin); build();//建树 int root1=-1,root2=-1; for(int i=0;i

ps:答案仅供参考,请勿抄袭

转载地址:http://nlqbi.baihongyu.com/

你可能感兴趣的文章
Ubuntu+win10远程桌面
查看>>
flutter-实现圆角带边框的view(android无效)
查看>>
flutter-实现一个下拉刷新上拉加载的列表
查看>>
android 代码实现圆角
查看>>
flutter-解析json
查看>>
android中shader的使用
查看>>
java LinkedList与ArrayList迭代器遍历和for遍历对比
查看>>
Android DataBinding使用2-Recycleview
查看>>
drat中构造方法
查看>>
JavaScript的一些基础-数据类型
查看>>
JavaScript基础知识(2)
查看>>
转载一个webview开车指南以及实际项目中的使用
查看>>
android中对于非属性动画的整理
查看>>
一个简单的TabLayout的使用
查看>>
关于let{a}=B出现的解构赋值
查看>>
ReactNative使用Redux例子
查看>>
Promise的基本使用
查看>>
android给文字加边框(修改不能居中的问题)
查看>>
coursesa课程 Python 3 programming 统计文件有多少单词
查看>>
coursesa课程 Python 3 programming 输出每一行句子的第三个单词
查看>>