1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string pal;
cin>>pal;
int ileA=0,ileB=0,d=pal.length();
for(int i=0; i<d; i++)
if(pal[i]=='a')
ileA++;
else ileB++;
if((ileA%2 && ileB%2 && d%2)||(d%2==0 && ileA%2==1 && ileB%2==1))
cout<<-1;
else
{
int wsk=d-1,ile=0;
for(int i=0; i<d/2; i++)
{
if(pal[i]!=pal[wsk])
ile++;
wsk--;
}
cout<<ile/2+ile%2;
}
return 0;
}
|