Chinaunix首页 | 论坛 | 博客
  • 博客访问: 23218
  • 博文数量: 19
  • 博客积分: 1447
  • 博客等级: 上尉
  • 技术积分: 195
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-29 18:40
文章分类

全部博文(19)

文章存档

2011年(4)

2010年(15)

我的朋友
最近访客

分类: C/C++

2010-12-15 08:51:56

//回文数程序

#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;
}


阅读(380) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-12-15 15:28:05

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com

chinaunix网友2010-12-15 15:28:05

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com