poj 2255 Tree Recovery 树的遍历 简单string用法
来源:互联网 发布:怎么在淘宝买二手表 编辑:程序博客网 时间:2024/05/17 02:36
给定前序和中序遍历,求后续遍历
用G++, c++会ce,string用着总感觉各种ce,不大会用,但这题用string真心容易些
前序遍历为 中左右 中序遍历为左中右
DBACEGF
ABCDEFG
粉色为左子树 D 为根 递归下去求即可
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;string dfs(string s1, string s2){ if( s1.length() == 1) return s1; if( s1.length() == 0) return ""; int m= s2.find(s1[0]); return dfs( s1.substr(1, m), s2.substr(0, m)) + dfs( s1.substr(m+1), s2.substr(m+1)) + s1.substr(0, 1);}int main(){//freopen("1.txt", "r", stdin);string str1, str2; while( cin>>str1>>str2 ){ cout<<dfs(str1, str2)<<endl; }return 0;}
string s1; cin>>s1; // abcdefghij cout<<s1.find('a')<<endl; // 0 cout<<s1.substr(1, 5)<<endl; // bcdef cout<<s1.substr(1)<<endl; // bcdefghij cout<<s1+"aaa"<<endl; // abcdefghijaaa cout<<s1.length()<<endl; // 10
- poj 2255 Tree Recovery 树的遍历 简单string用法
- POJ 2255 Tree Recovery 二叉树遍历
- POJ 2255 Tree Recovery (二叉树遍历)
- Poj 2255 Tree Recovery【dfs遍历树】
- POJ 2255 Tree Recovery 二叉树的遍历
- poj 2255 Tree Recovery(二叉树的遍历)
- POJ 2255 Tree Recovery(树的遍历)
- POJ 2255 Tree Recovery 树的遍历 水题
- poj 2255 Tree Recovery (二叉树的顺序遍历)
- POJ 2255 Tree Recovery 二叉树+遍历+递归
- poj 2255 Tree Recovery(求后序遍历,二叉树)
- POJ 2255 Tree Recovery(二叉树遍历)
- POJ 2255/hrbust 2022 Tree Recovery【dfs、二叉树的层次遍历】
- POJ 2255 Tree Recovery(根据前中序遍历,求后序遍历)
- poj2255~~Tree Recovery (树的遍历构造~)
- POJ2255 Tree Recovery 【树的遍历】
- poj 2255 Tree Recovery
- Tree Recovery---POJ--2255
- 用Jetty快速开发J2EE应用
- MFC设置按钮不可用
- juint测试之类工厂重构 mock objects测试
- Visual AssistX refactor功能初探
- BT5R3-GNOME-64中安装Flash插件……
- poj 2255 Tree Recovery 树的遍历 简单string用法
- hdu1166(敌兵布阵)
- 资源文件中对话框之控件的窗口类别和窗口样式
- 我是菜鸟,也是只努力的小鸟。
- javascript Closure
- android listview 圆角的实现方案,模仿Iphone的UITableView
- liunx压缩命令总汇
- 【控件相关】ListView的scrollbar快速定位
- 安全的“野指针”