### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

 why WA on test 5?? give me some test plz
Author: Taraneh
ID: 044030
Problem: -
Contest: -
Date: 2011-12-01 19:51:30

#include<iostream>
#include<string>
using namespace std;

const int maxn=1000+20;
int a[maxn], b[maxn];
string s;

int main(){
int x;
cin>>s;
for (int i=0; i<s.size(); i++){
if (s[i]=='(')
b[i]=1;
if (s[i]==')')
b[i]=-1;
}
for (int i=0; i<s.size(); i++){
if (i==0)
a[i]=b[i];
else
a[i]=a[i-1]+b[i];
}
int flag=0;
for (int i=0; i<s.size(); i++)
if (a[i]==2)
flag=1;
if (flag==0){
cout<<"No solution"<<endl;
return 0;
}
for (int i=s.size()-1; i>=0; i--)
if (a[i]==2 && b[i]==1 && (s.size()-i-1)%2==0){
b[i]=-1;
x=i;
break;
}
int cur=s.size()-x-1;
int ans=0;
for (int i=x+1; i<s.size(); i++){
ans++;
if (ans<=cur/2)
b[i]=1;
else if (ans>cur/2)
b[i]=-1;
}
for (int i=0; i<s.size(); i++){
if (b[i]==1)
cout<<'(';
else
cout<<')';
}
return 0;
}