3 条题解

  • 0
    @ 2025-1-22 16:09:34
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    const int N = 1210;
    char f[N];
    using namespace std;
    
    // 判断字符串 s 从 start 到 end 是否为回文串
    bool isPalindrome(char s[], int start, int end) {
        while (start < end) {
            if (s[start]!= s[end]) {
                return false;
            }
            start++;
            end--;
        }
        return true;
    }
    
    int main() {
        cin.getline(f, N);
        int q = strlen(f);
        for (int len = 2; len <= q; len++) {  // 枚举子串的长度
            for (int start = 0; start + len - 1 < q; start++) {  // 枚举子串的起始位置
                int end = start + len - 1;
                if (isPalindrome(f, start, end)) {  // 判断是否为回文串
                    for (int i = start; i <= end; i++) {
                        cout << f[i];
                    }
                    cout << endl;
                }
            }
        }
        return 0;
    }
    滑动窗口算法
    

    信息

    ID
    52
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    1050
    已通过
    156
    上传者