阅读程序(第二题):统计回文子串个数
阅读下面程序,完成后面的判断题和单选题。判断题正确填 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;
} 子题 判断题
判断题:当输入为 "aba" 时,输出为 4。( )
子题 判断题
判断题:将第 14 行的 `while (l < r)` 改为 `while (l <= r)` 后,程序对任何输入的输出结果都不变。( )
子题 判断题
判断题:对于长度为 n 的字符串,该程序输出的答案一定不超过 n。( )
子题 判断题
判断题:将第 15 行的 `s[l] != s[r]` 改为 `s[l] == s[r]` 后,当输入为 "aba" 时,输出为 5。( )
子题 单选题
当输入为 "aabba" 时,输出为( )。
子题 单选题
将第 16、17 行(`ok = false;` 与 `break;`)整体删去,使 if 语句体为空后,当输入为 "aba" 时,输出为( )。
子题 单选题
该程序的时间复杂度为( )。
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析