判断一个字符串是不是回文数

问题描述:判断一个字符串是不是回文数,比如abcdcba和abccba就是回文数。

代码:

 1 #include <stdio.h>
  2 #include <string.h>
  3
  4 #define MAX_SIZE 100
  5
  6 bool IsLoopString(char* str)
  7 {
  8     if(str==NULL) return false;
  9     int length=strlen(str);
 10     if(str[length-1]=='\n') length--;
 11     int start=0,end=length-1;
 12     while(start<end)
 13     {
 14         if(str[start++]!=str[end--]) return false;
 15     }
 16     return true;
 17 }
 18 int main(int argc,char *argv)
 19 {
 20     char str[MAX_SIZE];
 21     while(true)
 22     {
 23         char *ptr=fgets(str,MAX_SIZE,stdin);
 24         if(IsLoopString(ptr))
 25             printf("YES\n");
 26         else
 27             printf("NO\n");
 28     }
 29     return 0;
 30 }

Output:

[root@localhost Test]# ./a.out
abcdcba
YES
abccba
YES
abc cba
YES
abc\\0\\cba
YES
abc\00\cba
YES
abc\nn\cba
YES
abc\n\cba
YES

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值