十六章第二题

基本看的别人的,不会啊!
cctype字符函数库

#include<iostream>
#include<string>
#include<cctype>
using std::string;
using std::cout;
using std::cin;
bool fu(const string& str);
int main()
{
    
    
 string name;
 getline(cin, name);
 while (cin&&name.size()>0)
 {
    
    
  if (fu(name))
   cout << "yes\n";
  else
   cout << "no\n";
  getline(cin, name);
 }
 return 0;
}
bool fu(const string& str)
{
    
    
 string s = str;
 for (auto i = s.begin(); i != s.end();)
 {
    
    
  if (!isalpha(*i))  //是否为字母
  {
    
    
   i = s.erase(i);
   continue;
  }
  else
  {
    
    
   *i = tolower(*i);  //转换为小写
   i++;
  }
 }
 string f(s.rbegin(), s.rend());
 return (f == s);
}

猜你喜欢

转载自blog.csdn.net/wode_0828/article/details/108835944