题解 | 密码截取

密码截取

https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1

#include <stdio.h>
#include<string.h>
int main() {
    int out=0,count=0,len=0;
    char str[2501]={};
    scanf("%s",str);
    len=strlen(str);

    //模式1,aba, 以str[i]为基点,判断其左右两侧+j-j的数据是否一致,一致则count+2,进入j+1
    for(int i=1;i<len;i++){
        count=1;
        for(int j=1;j<((len+1)/2);j++){
            if(str[i+j]==str[i-j]){
                count+=2;
                continue;
            }
            else{
                break;
            }
        }
        if(count>out)out=count;
    }

    //模式2,abba,同理,先判断i和i+1,然后i+j和i+1+j
    for(int i=0;i<len;i++){
        count=0;
        for(int j=0;j<len/2;j++){
            if(str[i-j]==str[i+1+j]){
                count+=2;
                continue;
            }
            else{
                break;
            }
        }
        if(count>out)out=count;
    }
    

    printf("%d",out);
    return 0;
}

全部评论

相关推荐

爱吃肉的伊登在写日记:好棒,27届简历能做成这个样子,但是第一个项目感觉cover住难度还是不小的,特别是二面的时候肯定要对分布式系统设计这一块儿有高出正常面试者的水平才行
点赞 评论 收藏
分享
04-29 22:35
门头沟学院 Java
牛友说改了名字能收到offer:旧图新发查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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