

给定一个字符串s,可以在其前面添加字符a,判断该字符串能否变换成回文串,如果能输出Yse,不能说不出No


用字符串两边字符逐个比较,如果不同再判断后方是不是a字符
你题目的解答代码如下:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
getline(cin, s);
int l = 0, r = s.size()-1,f=1;
while (l<r)
{
if (s[l] == s[r])
{
l++;
r--;
f=0;
}
else if (f==1 && s[r]=='a')
{
r--;
}
else
{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!