代码
#include <bits/stdc++.h>
using namespace std;
int main(){
string s ;
cin >> s ;
string a = "" ;
int l = 0 ;
for ( int i = 0; i < s.size() ; i++ ) {
char c = s [ i ] ;
if ( c == '(' ) {
a += '(' ;
l++ ;
} else {
if ( l == 0 ) {
a += "()" ;
} else {
a += ')' ;
l-- ;
}
}
}
while ( l > 0 ) {
a += ')';
l-- ;
}
cout << a ;
return 0;
}