Sicily 1210 二叉树
2012-01-26 21:10
447 查看
关于树的前序和后序遍历,当前序遍历的第二个元素出现在后序遍历的倒数第二位,以后序遍历倒数第三位起向左数都是子树的元素,但是左右不确定,此时有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 二叉树 (Binary tree)
- Sicily 1210. 二叉树
- sicily 1210 二叉树
- sicily 1210 二叉树
- Sicily 1210 二叉树
- sicily 1210 二叉树
- [sicily]1210. 二叉树
- Sicily 1210. 二叉树
- Sicily1210.二叉树题解
- Sicily 1210. 二叉树
- Sicily 1210 二叉树
- Sicily 1210 二叉树(树的遍历)
- 【Sicily】1002. 等价二叉树
- sicily考试模拟题-1000超级和 1001会议室安排 1002二叉树比较
- zzuli 1210 二叉树(3) 用线索化二叉树和中跟输出两种方法
- 【Sicily】1002. 等价二叉树
- [sicily] 1002. 等价二叉树