-
Notifications
You must be signed in to change notification settings - Fork 0
/
1374C.cpp
52 lines (46 loc) · 1.53 KB
/
1374C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
#define F first
#define S second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define pb push_back
#define nl '\n'
#define nll cout<<'\n'
#define fr(n) for(int i=0; i<n; i++)
#define frr(n) for(int i=n-1;i>=0;i--)
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
bool isPowerOfTwo(ll n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}
bool isPerfectSquare(ll x){if (x >= 0) {ll sr = sqrt(x);return (sr * sr == x);}return false;}
// Mathematical functions
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);} //__gcd
ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}
ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)res = (res + a) % mod;b >>= 1;}return res;}
ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
int main() {
int t;
cin>>t;
while(t--){
ll n;
cin>>n;
string str;
stack <int> stk;
cin>>str;
fr(n){
if(str[i]==')'){
if(!stk.empty() && stk.top()=='(') stk.pop();
}
else stk.push(str[i]);
}
int count=0;
while(!stk.empty()) {
stk.pop();
count++;
}
cout<<count<<endl;
}
return 0;
}