题解 | #最长回文子串#

最长回文子串

https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507

#include <stdio.h>
#include <string.h>
#define max(x,y) ((x>y)?x:y)

int main() {
    char str[351]={0};
    scanf("%s",str);
    int lmax=0;
    int lc=0;
    for(int i=0;i<strlen(str);i++)
    {
        for(int j=(strlen(str)-1);j>=i;j--)
        { 
            int a,b;
            a=i;
            b=j;
            while(str[a]==str[b])
            {
                if((a==b-1)||(a==b))
                {
                    lc=lc+b-a+1;
                    lmax=max(lc,lmax);
                    break;
                }
                a++;
                b--;
                lc=lc+2;
            }
            lc=0;
            
        }
    }
    printf("%d",lmax);

}

全部评论

相关推荐

龙珠传说:nb,公务员解约不需要支付违约金吧
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务