Promi_38

cf 1374C

Jan 17th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int t;
  6.     scanf("%d", &t);
  7.    
  8.     while(t--)
  9.     {
  10.         int n;
  11.         scanf("%d", &n);
  12.         char s[n];
  13.         scanf("%s", s);
  14.         int i, c = 0, ans = 0;
  15.         for(i = 0; i < n; i++)
  16.         {
  17.             if(s[i] == '(') c++;
  18.             else c--;
  19.             if(c < 0)
  20.             {
  21.                 c = 0;
  22.                 ans++;
  23.             }
  24.         }
  25.         printf("%d\n", ans);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment