PAT (Advanced Level) 1040. Longest Symmetric String (25)

时间:2021-04-23 04:07:42

暴力。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; char s[];
int ans,len,sum; void check(int a,int b)
{
if(s[a]!=s[b]) return;
if(a==b) sum=; else sum=;
int left=a-,right=b+;
while(!(left<||right>=len||s[left]!=s[right]))
left--,right++,sum=sum+;
ans=max(ans,sum);
} int main()
{
gets(s);
len=strlen(s); ans=;
for(int i=;i<len;i++) check(i,i),check(i,i+);
printf("%d\n",ans);
return ;
}