Sicily 1210 二叉树
来源:互联网 发布:文明5汉化补丁mac 编辑:程序博客网 时间:2024/05/19 13:45
关于树的前序和后序遍历,当前序遍历的第二个元素出现在后序遍历的倒数第二位,以后序遍历倒数第三位起向左数都是子树的元素,但是左右不确定,此时有2种情况,计数器对应*2。最后吐槽一下坑爹的输出格式。
#include <stdio.h>#include <string.h>int ctr = 1;char s1[30];char s2[30];void solve( int x1, int y1, int x2, int y2 ) { int po,i; if ( x1>=y1 ) return; for ( i=x2;i<=y2;i++ ) { if ( s1[x1+1]==s2[i] ) { po=i; break; } } if ( po==y2-1 ) ctr=ctr*2; solve( x1+1, x1+1+po-x2, x2, po ); solve( x1+2+po-x2, y1, po+1, y2-1 );}int main(){ int l1,l2; while (scanf( "%s",&s1 )!=EOF ) { scanf( "%s",&s2 ); l1=strlen(s1); l2=strlen(s2); ctr=1; solve(0,l1-1,0,l2-1); printf( "%d",ctr ); } return 0;}
- Sicily 1210 二叉树
- sicily 1210 二叉树
- Sicily 1210(二叉树)
- Sicily 1210 二叉树
- Sicily 1210 二叉树
- Sicily 1210 二叉树(树的遍历)
- Sicily 1210. 二叉树
- Sicily 1210. 二叉树
- Sicily 1210. 二叉树
- Sicily 1210. 二叉树
- [sicily]1210. 二叉树
- sicily 1210. 二叉树
- Sicily 1935. 二叉树重建
- Sicily 1935. 二叉树重建
- sicily 1935. 二叉树重建
- Sicily 1935 二叉树重建
- Sicily 1935 二叉树重建
- Sicily 1935. 二叉树重建
- Visual C++ 中操纵 MS Word
- 什么是MVC以及PHP如何实现MVC
- imperfect C++读书笔记
- wpf 运行权限 解决不能写文件 创建文件夹问题
- 解决VS 编译 typedef void * POINTER_64 PVOID64错误
- Sicily 1210 二叉树
- ubuntu10.10 root用户没有声音(提示”正在等待声音系统响应”)
- 物体散射特性的问题
- MFC中快速应用OpenCV教程
- 构造器要轻量
- Video LightBox JS - a free wizard program that helps you easily embed video to website
- 视界
- 设定 <uses-sdk>以支持各种尺寸屏幕
- Sicily 1218 纪念邮票