Pagini recente » Cod sursa (job #2462350) | Cod sursa (job #679401) | Cod sursa (job #63710) | Cod sursa (job #1876436) | Cod sursa (job #2102965)
#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;
char s[205];
void perm( char *s)
{
char aux;
aux=s[0];
for(int i=0;i<strlen(s)-1;i++)
s[i]=s[i+1];
s[strlen(s)-1]=aux;
}
bool palindrom(char *s)
{
int i,n=strlen(s);
for(i=0;i<strlen(s)/2;i++)
if(s[i]!=s[strlen(s)-1-i]) return 0;
return 1;
}
int main()
{
freopen("palc.in","r",stdin);
freopen("palc.out","w",stdout);
int x,cnt=0;
gets(s);
int n=strlen(s);
while(palindrom(s)==0||cnt!=n)
{
if(cnt==n) break;
cnt++;
perm(s);
if(palindrom(s)==1) break;
}
if(cnt==n) printf("-1");
else
{
if(cnt>n/2) cnt=n-cnt;
printf("%d",cnt);
}
return 0;
}