My tutorial of "Codeforces Round 928 (Div. 4) A.Vlad and the Best of Five"

Revision en1, by optimize_ofast, 2024-02-21 07:35:40

This question is quite easy! We only need to input t sets of data and traverse each string. And use two counters, "suma" and "sumb", to determine the number of occurrences of letter A and letter B, and compare them. It is worth noting that the title has already mentioned that the length of the string is 5, so we do not need to determine whether suma is equal to sumb. Hope to see your comments!

Below is the AC code:

#include <bits/stdc++.h>
using namespace std;

int t;
int main() {
	cin >> t;
	while(t--) {
		string s;
		cin >> s;
		int suma = 0, sumb = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s[i] == 'A') suma++;
			else sumb++;
		}
		if(suma > sumb) cout << "A" << endl;
		else cout << "B" << endl;
	}
	return 0;
}
Tags implementations, brute force

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English optimize_ofast 2024-02-21 07:36:29 6
en1 English optimize_ofast 2024-02-21 07:35:40 851 Initial revision (published)