程序代码:
#include <stdio.h> #include <string.h> static char result[100], *p = result; static int count[2], i; void T(const char *str, int n) { for (i = count[0] = count[1] = 0; i < n; ++i) ++count[str[i]-'0']; if (count[0] == n) *p++ = 'A'; else if (count[1] == n) *p++ = 'B'; else { *p++ = 'C'; T(str, n/2); T(str + n/2, n/2); } } int main(void) { const char *str = "01001011"; T(str, strlen(str)); puts(result); return 0; }
My life is brilliant