|
|
back to boardWhy WA #11? Posted by prtest 21 Mar 2008 15:21 RT. #include<iostream> #include<string.h> using namespace std; int start,l,flag=1; char str[100010]; void init() { cin>>str; l=strlen(str); } int check(int a,int &now) { int i=a+1,count=1; if(str[a]==')') return 0; for(;i!=a;i++) { if(i==l) i=0; if(i==a) break; if(str[i]=='(') count++;else count--; if(count<0) {now=i+1;return 0;} } return 1; } void find() { int i,now; if(check(0,now)) {start=0;return;} for(i=1;i<l;i++) { if(str[i]=='(' && str[i-1]==')') if(check(i,now)) {start=i;return;}else i=now; } if(i==l) flag=0;return; } void solve() { int i,count=1,ans=0; if(flag==0) {cout<<0<<endl;return;} for(i=start+1;i!=start;i++) { if(i==l) i=0; if(i==start) break; if(str[i]=='(') count++;else count--; if(count==0) ans++; } cout<<ans<<endl; } int main() { init(); find(); solve(); return 0; } |
|
|