NextVox
← Back to the magazine
codingCompetitive6th grade

USACO Block Game

by Ethan · August 31, 2026

Hearts help pick each month’s winners.

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


vector<int> countfreqency(string letter) {
	vector<int> freqency(26);
	for (char c : letter) {
        freqency[c - 'a']++;
    }
	return freqency;
}

int main() {
	int N; cin >> N;

	vector<pair<string, string>> words;

    for (int i = 0; i < N; ++i) {
        string wordone;
        string wordtwo;
        cin >> wordone >> wordtwo;
        words.push_back({wordone, wordtwo});
    }

	vector<int> mxb(26);

    for (int j = 0; j < N; ++j) {
        vector<int> freqencyone = countfreqency(words[j].first);
        vector<int> freqencytwo = countfreqency(words[j].second);
        for (int k = 0; k < 26; k++) {
            mxb[k] += max(freqencyone[k], freqencytwo[k]);
        }
    }

    for (int a = 0; a < 26; ++a) {
        cout << mxb[a] << "\n";
    }
}