/*
回文判断
*/
#include <iostream>
using namespace std;
bool isHuiwen(char *str)
{
int len = strlen(str);
for(int index = 0;index < len/2;index++)
if(str[index] != str[len - 1- index])
return 0;
return 1;
}
int main()
{
char *s1 = "abcba";
char *s2 = "abcdcab";
if(isHuiwen(s1))
cout << s1 << ":" << "huiwen";
else
cout << s1 << ":" << "not huiwen";
if(isHuiwen(s2))
cout << s2 << ":" << "huiwen";
else
cout << s2 << ":" << "not huiwen";
return 0;
}华为机试——回文判断
最新推荐文章于 2024-10-07 18:41:59 发布
本文详细介绍了如何使用C++编程语言实现回文判断算法,通过定义一个函数isHuiwen来判断字符串是否为回文,并通过示例代码演示了实际应用。

3085

被折叠的 条评论
为什么被折叠?



