题解 | #密码截取#

密码截取

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

生硬的撕出来

#include<bits/stdc++.h>

using namespace std;

int main(){
    
    string str;
    cin>>str;
    int len=str.size();
    int max_c=1;
    for(int i=0;i<len;++i){
        int l=1;
        for(int j=1;j<=len/2&&i-j>=0&&i+j<len;++j){
            if(str[i-j]==str[i+j]){
                l++;
            }else{
                break;
            }
        }
        l=(l-1)*2+1;
        max_c = max(max_c,l);
        
        int l2=0;
        for(int j=1;j<=len/2&&i-j+1>=0&&i+j<len;++j){
            if(str[i-j+1]==str[i+j]){
                l2=j*2;
            }else{
                break;
            }
        }
        max_c = max(max_c,l2);
    }
    cout<<max_c<<endl;
    
    
    return 0;
}
全部评论

相关推荐

02-08 15:53
门头沟学院 Java
CoderEcho:让公司知道便宜没好货
点赞 评论 收藏
分享
1个小白:可以考虑投一下字节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务