JonsenElizee

Software Developing Blog

"An idea is fragile . It can be killed by a scornful smile or a yawn .It can be mound down by irony and scared to death by a cold look."
"Most cultures throughout human history have not liked creative individuals .They ignore them or kill them.It is a very efficient way of stopping creativity."

------Advertising boss Charles Browe and Howard Gardner ,professor at Harvard

   :: 首页 :: 新随笔 ::  ::  :: 管理 ::
Here is a simple palindrome algorithm from me.
It only can make a judge on single-byte character string.
Can anybody write a palindrome algorithm for Chinese character string? thank you at first.


posted on 2010-07-21 17:19 JonsenElizee 阅读(1328) 评论(1)  编辑 收藏 引用 所属分类: C++.BasicLinux.C++

评论

# re: My Palindrome Algorithm 2010-07-23 17:10 GRF

bool IsPalindrome(const char str[])
{
if (!str)
{
return true;
}

int len = strlen(str);
int i,j;
for (i=0,j=len-1;i<j;i++,j--)
{
if (str[i]<0) //中文字符
{
if ((str[i]!=str[j-1])||(str[i+1]!=str[j]))
{
break;
}
i+=2;
j-=2;
}
else //英文字符
{
if (str[i]!=str[j])
{
break;
}
i++;
j--;
}
}
return i>=j;
}  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


By JonsenElizee