#include <cstdio> #include <cstdlib> #include <iostream> #include <cassert> char buffer[100 * 1000 + 1]; int main() { int n; std::cin >> n; int ones = 0; for (int i = 0; i < 8 * n; i++) { char c; std::cin >> c; ones += (c == '1'); } if (ones < 3 * n || ones > 6 * n) { printf("NIE\n"); return 0; } ones -= 3 * n; for (int i = 0; i < n; i++) { if (ones >= 3) { buffer[i] = 'o'; ones -= 3; } else { if (ones == 2) { buffer[i] = 'g'; } else if (ones == 1) { buffer[i] = 'c'; } else { buffer[i] = 'a'; } ones = 0; } } buffer[n] = '\0'; puts(buffer); assert(ones == 0); 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 | #include <cstdio> #include <cstdlib> #include <iostream> #include <cassert> char buffer[100 * 1000 + 1]; int main() { int n; std::cin >> n; int ones = 0; for (int i = 0; i < 8 * n; i++) { char c; std::cin >> c; ones += (c == '1'); } if (ones < 3 * n || ones > 6 * n) { printf("NIE\n"); return 0; } ones -= 3 * n; for (int i = 0; i < n; i++) { if (ones >= 3) { buffer[i] = 'o'; ones -= 3; } else { if (ones == 2) { buffer[i] = 'g'; } else if (ones == 1) { buffer[i] = 'c'; } else { buffer[i] = 'a'; } ones = 0; } } buffer[n] = '\0'; puts(buffer); assert(ones == 0); return 0; } |