Codeforces 1374C. Move Brackets Solution
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t,n,i,cn;
- cin>>t;
- while(t--)
- {
- cin>>n;
- string s;
- cin>>s;
- cn=0;
- for(i=0; i<s.size(); i++)
- {
- if(s[i]=='(')
- cn++;
- else if((s[i]==')')&&(cn>0))
- cn--;
- }
- cout<<cn<<endl;
- }
- }
No comments