//回文数程序
#include <stdio.h> #include <string.h> #include <memory.h> //#include
#define MAX_LEN 80 char szInput[MAX_LEN+1]; unsigned char B[(MAX_LEN+1)*MAX_LEN/8];//感觉跟Bit8有关系,但具体说不出来什么
unsigned char Bit8[8]=;//看来是"位"操作
#define GETB(i,j) (B[(i)*10+((j)>>3)] & Bit8[(j) & 0x7]) #define SETB(i,j) (B[(i)*10+((j)>>3)] |= Bit8[(j) & 0x7]) int length; int getcode() { int i,j,notfound1,notfound2=0; if(length <2) return 1; //如果只输入两个字符,则返回1
memset(B,0,(length+1)*10);//MAX_LEN/8?
for(i=0;i <2;++i) { for(j=0;j <length;++j) SETB(i,j);//B[i][j]=1;
} for(i=2;i <=length;++i) { for(notfound1=1,j=0;j <=length-i;++j) { if(GETB(i-2,j+1)/*B[i-2][j+1]*/ && szInput[j]==szInput[j+i-1]) { SETB(i,j);//B[i][j]=1;
//printf("%d,%d = 1n",i,j);
notfound1=0; } } if(notfound1) { if(notfound2) return i-2; notfound2=1; } else { notfound2=0; } } if(notfound2) return length-1; return length; }
int main(void) {
while(scanf("%s",szInput)!=EOF) { length=strlen(szInput); //assert(length <=MAX_LEN);
printf("%dn",getcode()); } return 0; }
|