#include <cassert> #include <iostream> // 3 a // 4 c // 5 g // 6 o using namespace std; int main() { ios_base::sync_with_stdio(0); int i, n, s = 0; char c; cin >> n; for (i = 0; i < n * 8; i++) { cin >> c; if (c == '1') s++; } if (s < n * 3 || n * 6 < s) { cout << "NIE" << endl; return 0; } s -= n * 3; for (i = 0; i < n && s > 0; i++) { if (s >= 3) { cout << 'o'; s -= 3; } else if (s == 2) { cout << 'g'; s -= 2; } else if (s == 1) { cout << 'c'; s -= 1; } else { assert(false); } } for (; i < n; i++) { cout << 'a'; } cout << 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 36 37 38 39 40 41 42 43 44 45 46 | #include <cassert> #include <iostream> // 3 a // 4 c // 5 g // 6 o using namespace std; int main() { ios_base::sync_with_stdio(0); int i, n, s = 0; char c; cin >> n; for (i = 0; i < n * 8; i++) { cin >> c; if (c == '1') s++; } if (s < n * 3 || n * 6 < s) { cout << "NIE" << endl; return 0; } s -= n * 3; for (i = 0; i < n && s > 0; i++) { if (s >= 3) { cout << 'o'; s -= 3; } else if (s == 2) { cout << 'g'; s -= 2; } else if (s == 1) { cout << 'c'; s -= 1; } else { assert(false); } } for (; i < n; i++) { cout << 'a'; } cout << endl; return 0; } |