Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string s;
  8.     cin >> s;
  9.    
  10.     int bal = 0, k = 0, ans;
  11.     for(int i = 0; i < s.size(); i++)
  12.     {
  13.         if (s[i] == '(') bal++;
  14.         else bal--;
  15.        
  16.         if (bal < 0)
  17.         {
  18.             ans++;
  19.             bal++;
  20.         }
  21.     //  cout << bal << ' ' << k << ' ' << ans << '\n';
  22.     }
  23.     cout << ans + bal;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement