56求条

P1241 括号序列

bdcml @ 2024-08-04 19:59:38

#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin >> s;
    for(int i = 0;i < s.size();i++){
        if(s[i] == '(' or s[i] == ')'){
            if(s[i] == '(' and s[i+1] == ')'){
                cout << '(' << ')';
                i++;
                continue;
            }
            else cout << '(' << ')' ;
        } else if(s[i] == '[' or s[i] == ']'){
            cout << '[' << ']' ;
        }
    }
    return 0;
}

帮帮孩子吧


by WU_zehao @ 2024-08-05 08:32:50

哥们,菜


by WU_zehao @ 2024-08-05 08:33:36

玩几把原神你就回了!


by amd47802574 @ 2024-08-07 18:55:17

你题目意思理解错了,不是让单个括号变成两个括号挨在一起输出,建议你去看几个题解的评论,这题关系到顺序问题,使用栈最方便


by amd47802574 @ 2024-08-07 18:57:28

b站有讲解——>视频讲解


|