fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int f[50005];
  5. string s;
  6. void nhap_tinhf()
  7. {
  8. getline(cin,s);
  9. f[0]=0;
  10. for(int i=1;i<=s.length()-1;i++)
  11. if(s[i]=='('&&s[i-1]=='(')
  12. f[i]=f[i-1]+1;
  13. else
  14. f[i]=f[i-1];
  15. }
  16.  
  17. void giai()
  18. {
  19. int res=0;
  20. for(int i=1;i<=s.length()-1;i++)
  21. if(s[i]==')'&&s[i-1]==')')
  22. res=res+f[i];
  23. cout<<res;
  24. }
  25.  
  26. int main()
  27. {
  28.  
  29. nhap_tinhf();
  30. giai();
  31. }
  32.  
Success #stdin #stdout 0.01s 5280KB
stdin
)((()())())
stdout
4