Sohila_Elshiref

Regular Bracket Sequence

Oct 4th, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. string s;
  2.     cin >> s;
  3.     int c_r = 0, c_t = 0;
  4.     for (int i = 0; i < s.size(); i++)
  5.     {
  6.         if (s[i] == '(')
  7.         {
  8.             c_r++;
  9.         }
  10.         else if (s[i] == ')' && c_r != 0)
  11.         {
  12.             c_t++;
  13.             c_r--;
  14.         }
  15.     }
  16.     cout << c_t * 2;
Advertisement
Add Comment
Please, Sign In to add comment