第36599题 组合题
阅读程序(第二题):括号匹配与最大栈深

阅读下面程序,完成后面的判断题和单选题。判断题正确填 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;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
知识点:
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析