#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
char s[1000];
char t[1000];
int len;
int i, j;
memset(s, ‘\0‘, sizeof(s));
memset(t, ‘\0‘, sizeof(t));
while(gets(s)!=NULL )
{
len = strlen(s);
for( i=0; i<len; i++)
{
t[len-i-1] = s[i] ;
}
// puts(s);
// puts(t);
int max=0;
int cnt=0;
for(i=0; i<len; )
{
if( s[i]==t[i] )
{
j=i;
while( s[j]==t[j] && j<len )
{
cnt++;
j++;
}
if(cnt>max)
{
max = cnt; //max的值进行更新
cnt=0;
}
i = j ;
}
else
{
i++;
}
}
printf("%d\n", len-max );
}
return 0;
}
原文:http://www.cnblogs.com/yspworld/p/3963216.html