#include <iostream> #include <string_view> struct zak_t { uint32_t bytes; uint32_t num0; uint32_t num1; zak_t() : bytes(0) , num0(0) , num1(0) {} friend std::ostream& operator<<(std::ostream& out, zak_t const& zak) { out << zak.bytes << " [0:" << zak.num0 << ", 1:" << zak.num1 << "]\n"; return out; } friend std::istream& operator>>(std::istream& in, zak_t& zak) { in >> zak.bytes; char c; for (std::size_t i = 0; i < 8*zak.bytes; ++i) { in >> c; if (c == '0') { zak.num0 += 1; } else { zak.num1 += 1; } } return in; } }; zak_t read_input(std::istream& input) { zak_t zak; input >> zak; return zak; } char gen(uint32_t v) { switch(v) { case 3: return 'a'; case 4: return 'c'; case 5: return 'g'; case 6: return 'w'; }; return '0'; } uint32_t solution(std::istream& input, std::ostream& out) { auto zak = read_input(input); uint32_t result = 0; //out << zak; constexpr uint32_t min1 = 3; constexpr uint32_t max1 = 6; if (zak.bytes * min1 <= zak.num1 && zak.bytes * max1 >= zak.num1) { for(uint32_t i = zak.bytes; i > 0; --i) { uint32_t avg = zak.num1 / i; out << gen(avg); zak.num1 -= avg; } } else { out << "NIE" ; } return result; } #ifndef TEST int main(int argc, char* argv[]) { solution(std::cin, std::cout); return 0; } #endif
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <iostream> #include <string_view> struct zak_t { uint32_t bytes; uint32_t num0; uint32_t num1; zak_t() : bytes(0) , num0(0) , num1(0) {} friend std::ostream& operator<<(std::ostream& out, zak_t const& zak) { out << zak.bytes << " [0:" << zak.num0 << ", 1:" << zak.num1 << "]\n"; return out; } friend std::istream& operator>>(std::istream& in, zak_t& zak) { in >> zak.bytes; char c; for (std::size_t i = 0; i < 8*zak.bytes; ++i) { in >> c; if (c == '0') { zak.num0 += 1; } else { zak.num1 += 1; } } return in; } }; zak_t read_input(std::istream& input) { zak_t zak; input >> zak; return zak; } char gen(uint32_t v) { switch(v) { case 3: return 'a'; case 4: return 'c'; case 5: return 'g'; case 6: return 'w'; }; return '0'; } uint32_t solution(std::istream& input, std::ostream& out) { auto zak = read_input(input); uint32_t result = 0; //out << zak; constexpr uint32_t min1 = 3; constexpr uint32_t max1 = 6; if (zak.bytes * min1 <= zak.num1 && zak.bytes * max1 >= zak.num1) { for(uint32_t i = zak.bytes; i > 0; --i) { uint32_t avg = zak.num1 / i; out << gen(avg); zak.num1 -= avg; } } else { out << "NIE" ; } return result; } #ifndef TEST int main(int argc, char* argv[]) { solution(std::cin, std::cout); return 0; } #endif |