首页 > 其他 > 详细

判断回文字符串

时间:2016-02-23 11:08:56      阅读:137      评论:0      收藏:0      [点我收藏+]
1 #include "stdafx.h"
 2 #include "iostream"
 3 
 4 using namespace std;
 5 
 6 int isechol (const char* str)
 7 {
 8     int length = strlen(str);
 9     for (int i=0; i<length/2; i++)
10     {
11         // 0代表不是,1代表是
12         if (str[i] != str[length-i-1])
13         {    
14             return 0;
15         }
16     }
17     return 1;
18 }
19 
20 int main(int argc, char* argv[])
21 {
22     printf("Hello World!\n");
23     char buf[10] = "abcddcba";
24     if (isechol(buf))
25         cout << buf << " is echol" << endl;
26     else
27         cout << buf << " is not echol" << endl;
28     return 0;
29 }

输出:

Hello World!
abcddcba is echol
Press any key to continue

判断回文字符串

原文:http://www.cnblogs.com/zhiyewang/p/5209061.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!