#include <bits/stdc++.h> using namespace std; string s; int n, cnt[2]; void nie() { cout << "NIE\n"; exit(0); } void put(int c) { for (int i = 0; i < 5; i++) { if (c >> i & 1) cnt[1]--; else cnt[0]--; } s += (char)c; } int32_t main() { ios_base::sync_with_stdio(0); cin >> n >> s; for (auto i : s) cnt[i - '0']++; if (cnt[0] < n) nie(); if (cnt[1] < 2 * n) nie(); cnt[0] -= n, cnt[1] -= 2*n; s = ""; while (s.size() < n) { int x = cnt[0] - cnt[1]; //cout << x << endl; if (x > 2) put('a'); else if (x < -2) put('o'); else if (x >= 0) put('c'); else put('g'); } if (cnt[0] != 0 || cnt[1] != 0) nie(); cout << s << "\n"; }
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 | #include <bits/stdc++.h> using namespace std; string s; int n, cnt[2]; void nie() { cout << "NIE\n"; exit(0); } void put(int c) { for (int i = 0; i < 5; i++) { if (c >> i & 1) cnt[1]--; else cnt[0]--; } s += (char)c; } int32_t main() { ios_base::sync_with_stdio(0); cin >> n >> s; for (auto i : s) cnt[i - '0']++; if (cnt[0] < n) nie(); if (cnt[1] < 2 * n) nie(); cnt[0] -= n, cnt[1] -= 2*n; s = ""; while (s.size() < n) { int x = cnt[0] - cnt[1]; //cout << x << endl; if (x > 2) put('a'); else if (x < -2) put('o'); else if (x >= 0) put('c'); else put('g'); } if (cnt[0] != 0 || cnt[1] != 0) nie(); cout << s << "\n"; } |