,string字符串内部比较
求助,string字符串内部比较本帖最后由 u012941710 于 2014-01-02 16:26:11 编辑#includeiostream#includ
求助,string字符串内部比较
本帖最后由 u012941710 于 2014-01-02 16:26:11 编辑
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
bool isnot(const string&s);
int main()
{
cout << "Enter a string: ";
string str;
getline(cin, str);
if (isnot(str))
cout << "Yes,it is ";
else
cout << "No,it is not";
return 0;
}
bool isnot(const string&s)
{
string s1(s);
int x = 0;
for (int i = 0; i < s.size(); i++)
{
if (isalpha(s[i]))
{
s1[x] = tolower(s[i]);
x++;
}
}//我用cout<<s1看了下,貌似到这步都是正确的,但是之后得出的结论就没对
for (int i = 0; i <=x/2; i++)
{
if (s1[i] != s1[x-i])
return false;
}
return true;
}
题目的要求是,输入一个字符串,然后忽略空格标点大小写,然后要求判断是否是顺读和逆读都一样。
[解决办法]http://www.cplusplus.com/reference/string/string/compare/???
[解决办法]附上