题解 | #密码截取#

密码截取

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

#include <iostream>
using namespace std;

bool is_password(const char* begin, const char* end) {
    while (*begin == *end) {
        ++begin;
        --end;
    }
    return begin >= end;
}

int main() {
    string text;
    while (cin >> text) {
        int max_length = 1;
        for (size_t i = 0; i < text.size(); ++i) {
            const char c = text[i];
            string::size_type pos = text.size();
            do {
                pos = text.find_last_of(c, pos - 1);
                if (is_password(&text[i], &text[pos])) {
                    int length = pos - i + 1;
                    if (length > max_length) {
                        max_length = length;
                    }
                }
            } while (pos > i);

        }
        cout << max_length << endl;
    };
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

05-12 11:09
已编辑
门头沟学院 后端
已注销:没必要放这么多专业技能的描述。这些应该是默认已会的,写这么多行感觉在凑内容。项目这块感觉再包装包装吧,换个名字,虽然大家的项目基本都是网上套壳的,但是你这也太明显了。放一个业务项目,再放一个技术项目。技术项目,例如中间件的一些扩展和尝试。
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
06-19 14:58
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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