题解 | #密码截取#

密码截取

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")

全部评论

相关推荐

半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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