chapter16test2

来源:互联网 发布:mac系统重置密码 编辑:程序博客网 时间:2024/05/16 08:04
#include<iostream>
#include<string>
#include<cctype>
#include<iterator>
using namespace std;
string change(string str);
bool judge(string &str);
int main()
{
cout << "Enter a word(quit qo quit) :\n";
string str;
while (getline(cin, str) && str != "quit")
{
string s1 = change(str);
cout << s1 << endl;
if (judge(s1))
cout << str << ", True !\n";
else
cout << str << ", False !\n";
}
cout << "Finished !\n";
return 0;
}


string change(string str)
{
int num = str.size(); string rep;
for (int i = 0; i < num; i++)
{
if (isalpha(str[i]))
{
str[i]=tolower(str[i]);
rep = rep + str[i];
}
}
return rep;
}


bool judge(string &str)
{
int num = str.size(); string rep(str);
for (int i = 0; i < num; i++)
{
copy(str.rbegin(), str.rend(), rep.begin());
if (str == rep)
return true;
else
return false;
}
}
0 0
原创粉丝点击