#include
#include
#include
using namespace std;
bool R1(string s);
int main()
{
string s1;
while(getline(cin,s1)&&s1 !="q")
{
if(R1(s1))
cout<<s1<<"是回文.\n";
else
cout<<s1<<"不是回文.\n";
cout<<"请输入下一个字符串,输入q将退出\n";
}
return 0;
}
bool R1(string s)
{
string::iterator it;
for(it=s.begin();it!=s.end();++it)
{
*it=tolower(*it);
if(!isalnum(*it))
{s.erase(it);
}
}
cout<<s<<endl;
string val(s.rbegin(),s.rend());
if(val==s)
return true;
else
return false;
}

c++ string类的, 后的空字符无法消除
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-