力巴尔 @ 2021-10-04 16:40:59
#include <bits/stdc++.h>
using namespace std;
int s1[110];
int main()
{
string s;
cin>>s;
int l = s.length() - 1;
//for (int i = 0;i <= l;i++)
//s1[i] = '0';
for (int i = 0;i <= l;i++)
{
if (s[i] == ')')
{
for (int j = i - 1;j >= 0;j--)
{
if (s[j] == '(' && s1[j] == 0)
{
s1[i] = 1, s1[j] = 1;
break;
}
else if (s[j] == '(' && s1[j] == 1)
break;
}
}
}
for (int i = 0;i <= l;i++)
{
if (s[i] == ']')
{
for (int j = i - 1;j >= 0;j--)
{
if (s[j] == '[' && s1[j] == 0)
{
s1[i] = 1, s1[j] = 1;
break;
}
else if (s[j] == '[' && s1[j] == '1')
break;
}
}
}
for (int i = 0;i <= l;i++)
{
if (s1[i] == 1)
cout<<s[i];
else
{
if (s[i] == '(' || s[i] == ')')
cout<<"()";
else
cout<<"[]";
}
}
return 0;
}