文章

71

粉丝

97

获赞

5

访问

18.1k

头像
括号匹配南理工 为什么错误
我要提问
发布于2024年3月6日 15:48
阅读数 209

#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
using namespace std;

int main() {
    for (int j = 1; j <= 6; j++) {
        string st;
        cin >> st;
        stack<char> s;
        int length = st.size();
        for (int i = 0; i < length; i++) {
            if (st[i] == '[' || st[i] == '('||st[i]=='<'||st[i]=='{')
                s.push(st[i]);
            else if ((st[i] == ']' || st[i] == ')'||st[i] == '>' || st[i] == '}') && s.empty()) {
               &...

登录查看完整内容


登录后发布评论

1 条评论
snake
2024年3月6日 16:33

for循环括号范围有问题

赞(0)