Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string s;
  9. long b[100000];
  10. long balance=0;
  11. int k1=0;
  12. int k2=0;
  13. cin>>s;
  14. if (s.size()==1)
  15. {
  16. cout<<0;
  17. return 0;
  18. }
  19. for (long i=0; i<s.size(); i++)
  20. {
  21. if (s[i]=='(')
  22. {
  23. balance++;
  24. }
  25. else
  26. {
  27. balance--;
  28. }
  29. b[i] = balance;
  30. }
  31. if (balance!=0) {cout<<0;return 0;}
  32.  
  33. long minn=9999;
  34. long gcd=0;
  35. for (long i=0; i<s.size(); i++)
  36. {
  37. if (b[i]<minn)
  38. {
  39. minn=b[i];
  40. gcd = 1;
  41. }
  42.  
  43. else
  44. {
  45. if ( minn == b[i])
  46. {
  47. gcd++;
  48. }
  49. }
  50. }
  51. cout<<gcd;
  52. return 0;
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement