#include <bits/stdc++.h>
using namespace std;
struct node
{
char data;
struct node *lc, *rc;
};
char a[100],b[100];
int n;
struct node *creat(int len, char a[], char b[])
{
if(len == 0) return NULL;
int i;
struct node *root;
root = new node;
root -> data = a[0];
for(i = 0; i < len; i ++)
{
if(a[0] == b[i])
{
break;
}
}
root -> lc = creat(i, a + 1, b);
root -> rc = creat(len - i - 1,a + i + 1, b + i + 1);
return root;
};
int fin(struct node *root)
{
// cout << "yes" << endl;
int d1, d2;
int h = 0;
if(root)
{
d1 = fin(root -> lc);
d2 = fin(root -> rc);
h = max(d1+1,d2+ 1);
}
return h;
}
int main()
{
while(~scanf("%d",&n))
{
scanf("%s %s", a,b);
struct node *root;
root = creat(n,a,b);
int ans = fin(root);
printf("%d\n",ans);
} return 0;
}

数据结构实验之二叉树四:(先序中序)还原二叉树 (SDUT 3343)的更多相关文章

  1. 数据结构实验之链表四:有序链表的归并(SDUT 2119)

    #include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }; st ...

  2. SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树

    数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...

  3. SDUT-3343_数据结构实验之二叉树四:(先序中序)还原二叉树

    数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定一棵二叉树的先序遍历 ...

  4. SDUT OJ 数据结构实验之二叉树八:(中序后序)求二叉树的深度

    数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Probl ...

  5. SDUT-2804_数据结构实验之二叉树八:(中序后序)求二叉树的深度

    数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 已知一颗二叉树的中序 ...

  6. Java实现二叉树的前序、中序、后序遍历(非递归方法)

      在上一篇博客中,实现了Java中二叉树的三种遍历方式的递归实现,接下来,在此实现Java中非递归实现二叉树的前序.中序.后序遍历,在非递归实现中,借助了栈来帮助实现遍历.前序和中序比较类似,也简单 ...

  7. Java实现二叉树的前序、中序、后序、层序遍历(非递归方法)

      在上一篇博客中,实现了Java中二叉树的四种遍历方式的递归实现,接下来,在此实现Java中非递归实现二叉树的前序.中序.后序.层序遍历,在非递归实现中,借助了栈来帮助实现遍历.前序和中序比较类似, ...

  8. SDUT OJ 数据结构实验之图论四:迷宫探索

    数据结构实验之图论四:迷宫探索 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  9. SDUT OJ 数据结构实验之排序四:寻找大富翁

    数据结构实验之排序四:寻找大富翁 Time Limit: 200 ms Memory Limit: 512 KiB Submit Statistic Discuss Problem Descripti ...

  10. SDUT 3401 数据结构实验之排序四:寻找大富翁.!

    数据结构实验之排序四:寻找大富翁 Time Limit: 150MS Memory Limit: 512KB Submit Statistic Problem Description 2015胡润全球 ...

随机推荐

  1. 九、小程序 Redux详解与在小程序中怎么使用(action和reducers)

    什么是Redux ​ Redux我们可以把它理解成一个状态管理器,可以把状态(数据)存在Redux中,以便增.删.改.例如: 从服务器上取一个收藏列表,就可以把取回来的列表数据用Redux管理,多个页 ...

  2. Docker启动Elasticsearch报错java.nio.file.AccessDeniedException

    报错信息 Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes 问题分析 表面上是说容 ...

  3. Flutter学习之Dart语言基础(构造函数)

    最常见的构造函数形式,即生成构造函数,创建一个类的新实例: class Point { num x, y; //Dart中int和double是num的子类 //this引用当前类对象 Point(n ...

  4. nginx的so_keepalive和timeout相关小计

    KeepAlive 这里的keepalive是TCP的探活机制: [root@ ~]# sysctl -a |grep tcp_keepalive net.ipv4.tcp_keepalive_tim ...

  5. MySQL数据库---数据库管理

    -- 创建用户,指定明文密码create user 'rose'@'localhost' identified by 'rosepwd'; -- 查看用户是否创建成功select user,host ...

  6. mongodb索引 单键索引

    单键索引是最普通的索引,比如一条记录,形式为{x:1,y:2,z:3},我们在x上建立索引,之后就可以以x为条件进行查询,与_id索引不同,单键索引不会自动创建 创建索引 > db.test2. ...

  7. spark几个错误

    一.java.lang.NoSuchMethodError: net.jpountz.lz4.LZ4BlockInputStream.<init>(Ljava/io/InputStream ...

  8. MYSQL参数说明

    [mysqld] character_set_server=utf8 #慢日志时间 long_query_time=1 #开启慢日志 slow_query_log=TRUE #慢日志位置 slow_q ...

  9. 1121 Django基本

    目录 Django前戏 一.课程导读 1.web应用 2.c/s b/s 架构 3.Python Web框架 二.原生socket服务 三.http协议 什么是http协议 四大特性 http工作原理 ...

  10. nginx中ngx_http_core_module模块

    http核⼼心模块指令:套接字相关的配置3.1 server{ }设置虚拟服务器器的配置Syntax: server { ... }Default: —Context: httpserver {lis ...