gongchang24061426 @ 2024-09-24 20:46:19
#include<stdio.h>
int main()
{
char l[101];
scanf("%s", l,101);
int judge[101] = { 0 };
for (int i = 0; l[i]!='\0'; i++)
{
if (l[i] == ')')
{
for (int a = i-1; a >= 0; a--)
{
if ((l[a] == '('||l[a]=='[') && judge[a] == 0)
{
if (l[a] == '(')
{
judge[i] = 1;
judge[a] = 1;
}
break;
}
}
}
if (l[i] == ']')
{
for (int a = i - 1; a >= 0; a--)
{
if (l[a] == '(' || l[a] == '[' && judge[a] == 0)
{
if (l[a] == '[')
{
judge[i] = 1;
judge[a] = 1;
}
break;
}
}
}
}
for (int i = 0; l[i]!='\0'; i++)
{
if (judge[i] == 1)
printf("%c", l[i]);
else
{
if (l[i] == ')')
printf("()");
if (l[i] == ']')
printf("[]");
if (l[i] == '(')
printf("()");
if (l[i] == '[')
printf("[]");
}
//printf("%d", judge[i]);
}
return 0;
}