求助,有一道题我怎么也做不出来
输入一个长为2^k(k≤8)01串s,按照"ABC编码规则"进行编码,ABC编码规则是:{ A //若s串全是0
T(s)={ B //若s串全是1
{ CT(s1)(s2) //否则把s串分成两个等长的字串s1和s2
例如:
T(01001011)
=CT(0100)T(1011)
=CCT(01)T(00)CT(10)T(11)
=CCCT(0)T(1)ACCT(1)T(0)B
=CCCABACCBAB
#include<stdio.h> #include<conio.h> #include<string.h> #define N 256 char a[N]; void Trans(int x, int y); void Trans(int x, int y) { int i, flag=0; for(i=x; i<=y; i++) { if(a[i] == 48) flag =flag + 1; else flag =flag - 1; } if(flag == y-x+1) printf("A"); else { if(flag == x-y-1) printf("B"); else { printf("C"); Trans(x, (x+y-1)/2); Trans((x+y+1)/2, y); } } } void main(void) { int x, y; printf("请输入长为2^k(k<=8)的01串(按回车结束输入):" ); scanf("%s",a); x = 0; y = strlen(a)-1; Trans(x, y); getch(); }