阅读程序(第二题):括号匹配与最大栈深
阅读下面程序,完成后面的判断题和单选题。判断题正确填 A,错误填 B。
#include <cstdio>
#include <cstring>
char s[100005];
char st[100005];
int main() {
scanf("%s", s);
int n = strlen(s);
int top = 0, pairs = 0, dep = 0, mx = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '(') {
st[++top] = '(';
dep = top;
if (dep > mx) mx = dep;
} else if (s[i] == ')') {
if (top > 0) {
--top;
++pairs;
}
}
}
printf("%d %d\n", pairs, mx);
return 0;
} 子题 判断题
判断题:当输入为 "((()))" 时,输出的第二个数为 3。( )
子题 判断题
判断题:将第 17 行的 `if (top > 0) {` 改为 `if (top >= 0) {` 后,当输入为 "())(" 时,输出的第一个数为 2。( )
子题 判断题
判断题:当输入为 "(()" 时,输出的两个数之和为 4。( )
子题 判断题
判断题:当输入为 ")(" 时,输出的两个数都是 0。( )
子题 单选题
当输入为 "()(())" 时,输出为( )。
子题 单选题
将第 14 行的 `dep = top;` 改为 `dep = top + 1;` 后,当输入为 "((()))" 时,输出的第二个数为( )。
子题 单选题
该程序的时间复杂度为( )。
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析