Short & Easier Solution to C. Even Positions from last contest.

Revision en1, by amnchouhn, 2024-08-03 01:20:44

I have found a very short solution of 1997C - Even Positions compared to what's available everywhere. Please upvote if found helpful.

#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();}
}
Tags greedy

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)