#include #include using namespace std; int d[100][100]; //d[i][j]表示输入字符串从下标i到下标j至少需要加的括号数 int c[100][100]={-1}; //c[i][j]表示从下标i到下标j的子串分割的下标,-1表示不分割 int len; //输入括号串的长度 string s; //输入的括号串 void dp() { int i,j,k,l; int min; for(i=0; ij) return; if(i==j) { if(s[i]=='(' || s[i]==')') cout<<"()"; else cout<<"[]"; } else { if(c[i][j]>=0) //从i到j从c[i][j]处分割 { print(i, c[i][j]); print(c[i][j]+1, j); } else { if(s[i]=='(') { cout<<"("; print(i+1, j-1); cout<<")"; } else { cout<<"["; print(i+1, j-1); cout<<"]"; } } } } int main() { cin>>s; //输入括号序列 len=s.size(); dp(); print(0, len-1); cout<