Captain_Von @ 2017-09-03 13:26:18
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[120];
int a[120],len;
void print(int p)
{
if(s[p]=='(' || s[p]==')')
cout<<"()";
else
cout<<"[]";
}
int main()
{
scanf("%s",s+1);
len=strlen(s+1);
for(int i=1;i<=len;i++)
{
if(s[i]=='(')
a[i]=1;
else if(s[i]==')')
a[i]=-1;
else if(s[i]=='[')
a[i]=2;
else
a[i]=-2;
}
int i,j;
for(j=i,i=1;i<=len;i++)
{
if(a[i]<0)
{
while(j>=1)
{
j--;
if(a[i]+a[j]==0)
{
a[i]=a[j]=0;
break;
}
}
}
}
for(int ii=1;ii<=len;ii++)
if(a[ii]==0)
cout<<s[ii];
else
print(ii);
return 0;
}
by Captain_Paul @ 2017-10-12 19:01:20
这么巧,我也63分