#include <iostream> #include <cstdio> #include <string> char decode[] = { 'a', 'c', 'g', 'o' }; int main() { int n; std::string in; std::cin >> n >> in; int ones = 0; for (int i = 0; i < in.length(); ++i) { if (in[i] == '1') ++ones; } ones -= 3 * n; if (ones < 0 || ones > 3 * n) { std::cout << "NIE" << std::endl; return 0; } int base = ones / n; int more = ones % n; std::string answer; for (int i = 0; i < n; ++i) { if (i < more) { answer.push_back(decode[base + 1]); } else { answer.push_back(decode[base]); } } std::cout << answer << std::endl; 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 <iostream> #include <cstdio> #include <string> char decode[] = { 'a', 'c', 'g', 'o' }; int main() { int n; std::string in; std::cin >> n >> in; int ones = 0; for (int i = 0; i < in.length(); ++i) { if (in[i] == '1') ++ones; } ones -= 3 * n; if (ones < 0 || ones > 3 * n) { std::cout << "NIE" << std::endl; return 0; } int base = ones / n; int more = ones % n; std::string answer; for (int i = 0; i < n; ++i) { if (i < more) { answer.push_back(decode[base + 1]); } else { answer.push_back(decode[base]); } } std::cout << answer << std::endl; return 0; } |