题解
2023-09-01 10:43:37
发布于:广东
1阅读
0回复
0点赞
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> count_freq(string s) {
vector<int> freq(26);
for (char c : s) { freq[c - 'a']++; }
return freq;
}
int main() {
int n;
cin >> n;
vector<pair<string, string>> words(n);
for (auto &[w1, w2] : words) { cin >> w1 >> w2; }
vector<int> max_blocks(26);
for (const auto &[w1, w2] : words) {
vector<int> freq1 = count_freq(w1);
vector<int> freq2 = count_freq(w2);
for (int c = 0; c < 26; c++) {
max_blocks[c] += max(freq1[c], freq2[c]);
}
}
for (int i : max_blocks) { cout << i << '\n'; }
}
这里空空如也
有帮助,赞一个