第36550题 组合题
阅读程序(第二题):统计回文子串个数

阅读下面程序,完成后面的判断题和单选题。判断题正确填 A,错误填 B。

#include <cstdio>
#include <cstring>

char s[5005];

int main() {
    scanf("%s", s);
    int n = strlen(s);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            int l = i, r = j;
            bool ok = true;
            while (l < r) {
                if (s[l] != s[r]) {
                    ok = false;
                    break;
                }
                ++l;
                --r;
            }
            if (ok) ++ans;
        }
    }
    printf("%d\n", ans);
    return 0;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
知识点:
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析