#include <iostream> namespace { using std::cin; using std::cout; using std::getline; using std::stoull; using word_t = std::string; inline char const ONE = '1'; inline char const KEY_BY_ONES[] = { 'a', 'c', 'g', 'o' }; } int main() { word_t n_word; size_t n; word_t bin_word; size_t bin_word_size; size_t zeros = 0, ones = 0; getline(cin, n_word); n = stoull(n_word); getline(cin, bin_word); bin_word_size = bin_word.size(); for (size_t k = 0; k < bin_word_size; ++k) if (bin_word[k] == ONE) ++ones; else ++zeros; if (ones < 3 * n || ones > 6 * n || zeros < 2 * n || zeros > 5 * n) { cout << "NIE"; return 0; } word_t message; size_t r; zeros -= n; ones -= 2 * n; r = zeros % n; if (r == 0) r = n; for (size_t k = 0; k < r; ++k) message.push_back(KEY_BY_ONES[ones / n - 1]); r = ones % n; for (size_t k = 0; k < r; ++k) message.push_back(KEY_BY_ONES[ones / n]); cout << message; 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <iostream> namespace { using std::cin; using std::cout; using std::getline; using std::stoull; using word_t = std::string; inline char const ONE = '1'; inline char const KEY_BY_ONES[] = { 'a', 'c', 'g', 'o' }; } int main() { word_t n_word; size_t n; word_t bin_word; size_t bin_word_size; size_t zeros = 0, ones = 0; getline(cin, n_word); n = stoull(n_word); getline(cin, bin_word); bin_word_size = bin_word.size(); for (size_t k = 0; k < bin_word_size; ++k) if (bin_word[k] == ONE) ++ones; else ++zeros; if (ones < 3 * n || ones > 6 * n || zeros < 2 * n || zeros > 5 * n) { cout << "NIE"; return 0; } word_t message; size_t r; zeros -= n; ones -= 2 * n; r = zeros % n; if (r == 0) r = n; for (size_t k = 0; k < r; ++k) message.push_back(KEY_BY_ONES[ones / n - 1]); r = ones % n; for (size_t k = 0; k < r; ++k) message.push_back(KEY_BY_ONES[ones / n]); cout << message; return 0; } |