ZYK_luogu @ 2023-04-30 18:44:33
#include <iostream>
#include <cstring>
using namespace std;
#deine maxn 105
char get(char c) {
switch(c) {
case '(':
return ')';
case ')':
return '(';
case '[':
return ']';
case ']':
return '[';
}
}
int main() {
string str;
cin >> str;
int point[maxn], len = str.length();
memset(point, 0, sizeof(point));
for(int i = 1; i < len; i ++)
if(str[i - 1] == get(str[i]))
point[i] = point[i - 1] = 1;
for(int i = 0; i < len; i ++)
if(point[i])
cout << str[i], i ++;
else
if(str[i] == '(' || str[i] == '[')
cout << str[i] << get(str[i]);
else
cout << get(str[i]) << str[i];
return 0;
}
by dgy0626 @ 2023-05-13 11:32:35
用栈吧