Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 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.         if (bal+k < 0)
  16.         {
  17.             ans++;
  18.             k++;
  19.         }
  20.     }
  21.     cout << ans + bal;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement