fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. int n;
  6. cin >> n;
  7. string s;
  8. cin >> s;
  9. int ans = 1;
  10. for (int i = 1; i < 2 * n - 1; i++) {
  11. if (s[i] == '(') {
  12. if (s[i - 1] == '(') {
  13. ans++;
  14. }
  15. }
  16. }
  17. cout << ans << endl;
  18. }
  19.  
  20. int main() {
  21. // your code goes here
  22. int t;
  23. cin >> t;
  24. while (t--) solve();
  25. }
Success #stdin #stdout 0s 5288KB
stdin
5
1
()
3
()(())
3
((()))
4
(())(())
9
(())(((())))(()())
stdout
1
2
3
3
6