首页 > 其他 > 详细

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

时间:2014-09-09 20:01:39      阅读:219      评论:0      收藏:0      [点我收藏+]
#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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!