RE球调
查看原帖
RE球调
1277657
Yaoshui_lv楼主2024/8/23 10:59
#include <iostream>
#include <string>
#define len s.length() 
using namespace std;

int  q[100001], top;
string s, t;

int main() {
	#ifndef ONLINE_JUDGE
	    freopen("in.txt", "r", stdin);
	    freopen("out.txt", "w", stdout);
	#endif
    cin >> s;
    for (int i = 0; i < len; i++) {
        if (s[i] == '(') {q[++top] = i; t[i]=')';}
        if (s[i] == '[') {q[++top] = i; t[i]=']';}
        if (s[i] == ')' || s[i] == ']')
            if (!top || t[q[top]] != s[i])
                if (s[i] == ')') t[i] = '(';
				else t[i] = '[';
            else t[q[top--]] = ' ';
    }
    for (int i = 0; i < len; i++) {
        if (t[i] == '(' || t[i] == '[') cout << t[i];
        cout << s[i];
        if (t[i] == ')' || t[i] == ']') cout << t[i];
    }
    return 0;
}
2024/8/23 10:59
加载中...