解题思路:
1.使用A.insert()将字符串B插入到A中,构成一个新的字符串,一共有 A.size()+1种可能。
2.判断产生的新的字符串是否是回文串。
#include<iostream>
#include<string>
using namespace std;
bool IsCircle(const string& str)//判断一个字符串是否是回文串
{
int begin=0;
int end = str.size()-1;
while(begin < end)
{
if(str[begin] != str[end])
return false;
++begin;
--end;
}
return true;
}
int main()
{
string str1,str2;
getline(cin,str1);
getline(cin,str2);
int count =0;
for(int i= 0 ;i <= str1.size() ;++i) //最后位置也要插入
{
string temp = str1; //临时的一个string,不修改原字符串
temp.insert(i,str2);
if(IsCircle(temp))
count++;
}
cout << count <<endl;
return 0 ;
}