记录编号 94462 评测结果 WWWWWWWWWW
题目名称 1050.[Citric S2] 柠檬的密码 最终得分 0
用户昵称 紫葉 是否通过 未通过
代码语言 C 运行时间 0.003 s
提交时间 2014-04-01 10:21:26 内存使用 0.39 MiB
显示代码纯文本
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char str[100000];

int main(int argc, char *argv[]) {
	
	int n,x;// 1=<x<=n/2 
	int i,j,t,k,max=0,sum,len;
	int tot;
	freopen("password.in ","r",stdin);
	freopen("password.out","w",stdout);
	
	scanf("%d",&n);
	scanf("%s",str);
//	printf("n=%d  %s",n,str);
	for(i=0;i<=n-3;i++)
	{
		tot=0;
		sum=0;
	    t=i;
	    k=n-1;
	    while(str[t]!=str[k]&&k>=t+2) k--;
	//    if(k>=t+2) tot++;
	    while(str[t]==str[k]&&k>=t+2)
	    {
	    	t++;
	    	k--;
	    	tot++;
	    }
	    sum=sum+tot*2;
   //     printf("sum=%d\n",sum);
		tot=0;
	    for(j=t;j<=k;j++)
	    {
	    	len=0;
	    	for(x=1;j-x>=t&&j+x<=k;)
	    	{
	    		if(str[j-x]==str[j+x]) x++; 
	    		else
	    		break;
	    	}
	    	len=(x-1)*2+1;
	    	if(len>tot) tot=len;
	    }
	    sum=sum+tot;
	    if(sum>max) max=sum;
	}
	
	printf("%d\n",max);
	
	return 0;
}