#include <bits/stdc++.h> using namespace std; unordered_map<int,char> ratio_to_letter = { {3, 'a'}, {4, 'c'}, {5, 'g'}, {6, 'o'} }; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; string bits; cin >> bits; size_t count_one = std::count(bits.begin(), bits.end(), '1'); size_t ratio = count_one / n; if (ratio <= 2 || (ratio == 6 && count_one % n != 0) || 7 <= ratio) { cout << "NIE"; return 0; } size_t count = n - (count_one % n); string res = string(count, ratio_to_letter[ratio]) + string(n - count, ratio_to_letter[ratio + 1]); cout << res; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <bits/stdc++.h> using namespace std; unordered_map<int,char> ratio_to_letter = { {3, 'a'}, {4, 'c'}, {5, 'g'}, {6, 'o'} }; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; string bits; cin >> bits; size_t count_one = std::count(bits.begin(), bits.end(), '1'); size_t ratio = count_one / n; if (ratio <= 2 || (ratio == 6 && count_one % n != 0) || 7 <= ratio) { cout << "NIE"; return 0; } size_t count = n - (count_one % n); string res = string(count, ratio_to_letter[ratio]) + string(n - count, ratio_to_letter[ratio + 1]); cout << res; return 0; } |