#include <bits/stdc++.h> using namespace std; // a->3, c->4, g->5, o->6 string litery[4] = {"a", "c", "g", "o"}; int coins[4] = {0, 1, 2, 3}; int n, res, ones; string s; string coinchange(int x) { string res = ""; int cur = 3; while (res.length() < n) { while (coins[cur] > x) --cur; x -= coins[cur]; res += litery[cur]; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; for (char &c : s) ones += (c == '1'); if (n * 6 < ones || n * 3 > ones) cout << "NIE\n"; else cout << coinchange(ones - n * 3) << '\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 | #include <bits/stdc++.h> using namespace std; // a->3, c->4, g->5, o->6 string litery[4] = {"a", "c", "g", "o"}; int coins[4] = {0, 1, 2, 3}; int n, res, ones; string s; string coinchange(int x) { string res = ""; int cur = 3; while (res.length() < n) { while (coins[cur] > x) --cur; x -= coins[cur]; res += litery[cur]; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; for (char &c : s) ones += (c == '1'); if (n * 6 < ones || n * 3 > ones) cout << "NIE\n"; else cout << coinchange(ones - n * 3) << '\n'; } |