原来如此!!果然巧妙,飞燕功底非我等凡俗所能达到的啊……真心仰慕……
与LZ思路接近的一个算法
#include <stdio.h> #include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream.h>
void main()
{
char *p, inputletter, myletter;
int k, i, j, mid;
long size;
scanf("%c", &inputletter);
k = inputletter - 64;
size = (long )(pow(2, k) - 1);
p = (char *)malloc(size);
p[0] = 65;
myletter = 65;
mid = 0;
while (myletter <= inputletter)
{
p[mid] = myletter;
i = mid - 1;
j = mid + 1;
for (;;i--, j++)
{
if(i < 0)
{
j = j - 1;
break;
}
p[j] = p[i];
}
mid = j + 1;
myletter += 1;
}
puts(p);
free(p);
}
LZ的错误没仔细看,但是一开始处的for循环就出错了,申请空间应该是一次性的!