过不了编译

P1241 括号序列

glzx004 @ 2024-02-02 16:48:56

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

int main() {
    string s;
    cin >> s;
    stack<char> kh;
    string da = "";

    for (char c : s){
        if (c == '(' || c == '[') {
            kh.push(c);
        } else if (c == ')' || c == ']') {
            if (!kh.empty() && (kh.top() == '(' && c == ')' || kh.top() == '[' && c == ']')) {
                kh.pop();
            } else {
                da += "()";
                da += c;
            }
        }
    }

    while (!kh.empty()) {
        da += kh.top();
        da += "()";
        kh.pop();
    }

    cout << da;
}

by ZZZZZhanggggg @ 2024-02-02 16:54:03

我用vscode可以编译啊


|