标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11939 | Accepted: 7493 |
Description
D
/
/
B E
/ \
/ \
A C G
/
/
F
Input
Output
Sample Input
DBACEGF ABCDEFG BCAD CBAD
Sample Output
ACBFGED CDAB
Source
1 #include <stdio.h> 2 char in[27],pre[27],*pr; 3 void maketree(char *in) 4 { 5 char *mid,tmp; 6 if(*in==‘\0‘) 7 return; 8 //mid = strchr(in,*pr++); 9 for(mid=in;*mid!=*pr;) 10 mid++; 11 pr++; 12 13 tmp = *mid; 14 *mid = ‘\0‘; 15 mid++; 16 maketree(in); 17 maketree(mid); 18 putchar(tmp); 19 } 20 int main() 21 { 22 while(scanf("%s%s", pre, in) == 2) { 23 pr=pre; 24 maketree(in); 25 putchar(‘\n‘); 26 } 27 return 0; 28 }
我的递归里面因为不是用下标处理的,也没在参数里加长度来判断,所以显得麻烦点。如果加了长度判断,则几行就搞定了(代码来自SCNU变态的小liming):
1 void solve(char*a,char*b,int L){ 2 char*i; 3 if(L){ 4 i=strchr(b,*a); 5 solve(a+1,b,i-b); 6 solve(a-b+i+1,i+1,b+L-i-1); 7 putchar(*a); 8 } 9 }
标签:
原文地址:http://www.cnblogs.com/BlackStorm/p/4268597.html