Short & Easier Solution to C. Even Positions from last contest.
Difference between en1 and en2, changed 68 character(s)
I have found a very short solution of [problem:1997C] compared to what's available everywhere.↵
Please upvote if found helpful.↵

[user:Shayan,2024-08-03] Is there any edge case for this solution?↵

~~~~~↵
#include <bits/stdc++.h>↵
using namespace std;↵
#define nl '\n'↵
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);↵

void solve() {↵
int n; cin >> n;↵
string s; cin >> s;↵
int ans = 0;↵
for (int i = 0; i < n; i += 2) {↵
if (s[i + 1] == ')') {↵
ans += 1;↵
}↵
else {↵
ans += 3;↵
}↵
}↵
cout << ans << nl;↵
}↵

int main() {↵
FAST_IO↵
int tc; cin >> tc;↵
while (tc--) {solve();}↵
}↵
~~~~~↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English amnchouhn 2024-08-03 01:28:05 104
en2 English amnchouhn 2024-08-03 01:24:14 68
en1 English amnchouhn 2024-08-03 01:20:44 628 Initial revision (published)