_HHJ @ 2022-09-05 09:54:08
#include <stack>
#include <iostream>
using namespace std;
typedef pair<char,int> PII;
stack<PII>kh;
stack<PII>dkh;
bool flag[150];
int main()
{
string a;
cin >> a;
for (int i = 0 ; i < a.size() ; i ++ )
{
if(a[i] == '(')kh.push({a[i],i});
if(a[i] == '[')dkh.push({a[i],i});
if(a[i] == ')' && kh.size()){flag[kh.top().second] =flag[i]= 1;kh.pop();}
if(a[i] == ']' && dkh.size()){flag[dkh.top().second] = flag[i] = 1;dkh.pop();}
}
for(int i = 0 ; i < a.size() ; i ++ )
{
if(!flag[i])
{
if(a[i] == '('||a[i] == ')')
cout << "()";
if(a[i] == '['||a[i] == ']')
cout << "[]";
}
else
cout << a[i];
}
}a