原串与其逆序串 对应位置且 连续最大长度

#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, '', sizeof(s));
	memset(t, '', 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
", len-max );
	}
 	return 0;
}
原文地址:https://www.cnblogs.com/yspworld/p/3963216.html