C++判断回文程序修改,要求:滤去所有非字母字符(包括空格)后,不考虑字母的大小写,从左向右和从右

C++判断回文程序修改,要求:滤去所有非字母字符(包括空格)后,不考虑字母的大小写,从左向右和从右向左读都相同的词或者短语!

#include<iostream>

using namespace std;
#define SIZE 100

int main()
{
//Test_Deviation();
//Test_V();
char carray[SIZE] = { 0 };
int i, len, is_palindrome = 1;
cout << "Please input a string.\n";
cin.get(carray, SIZE - 1);
len = strlen(carray);
// 去掉非字母字符
char carray2[SIZE] = { 0 };
int j = 0;
for (i = 0; i < len; i++)
{
if ((carray[i] >= 'a' && carray[i] <= 'z') ||
(carray[i] >= 'A' && carray[i] <= 'Z'))
carray2[j++] = carray[i];
}
// 判断回文
for (i = 0; i < j; i++)
{
if ((carray2[i] != carray2[j - 1 - i]) && 
(carray2[i] + 32 != carray2[j -1 - i]) && 
(carray2[i] != carray2[j - 1 - i] + 32))
{
is_palindrome = 0;
break;
}
}

if (is_palindrome != 0)cout << "The string is a palindrome.\n";
else cout << "The string isn't a palindrome.\n";

return 0;
}




朋友,请【采纳答案】,您的采纳是我答题的动力,如果没有明白,请追问。谢谢。

温馨提示:答案为网友推荐,仅供参考