题解 | #密码截取#

密码截取

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

#include <iostream>
#include <stdexcept>
using namespace std;

int main() {
    string str;
    getline(cin, str);
    int maxc = 0;
    int sy;
    for (int i = 0; i < str.length(); i++) {
        sy = i;
        int pos = 1, count = 0;
        while (str[i] == str[i + pos]) {
            count += 2;
            if (i == 0 || i + pos == str.length()-1) break;
            i --;
            pos += 2;
        }
        i = sy;
        pos =1;
        maxc = max(count, maxc);
        count =0;
        while (str[i - pos] == str[i + pos]) {
            if (count == 0) count = 1;
            count += 2;
            if (i - pos <= 0 || i + pos >= str.length()-1) break;
            pos ++;
        }
        maxc = max(count, maxc);
    }
    cout << maxc << endl;
}

全部评论

相关推荐

05-19 15:21
已编辑
门头沟学院 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 11:33
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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