#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); map<int, char> M = {{-2, 'a'}, {0, 'c'}, {2, 'g'}, {4, 'o'}}; int n; cin >> n; string s; cin >> s; int cnt = -2 * count(s.begin(), s.end(), '0') + 8*n; string res; while (n--) { int delta = clamp(cnt, -2, 4); cnt-=delta; res+=(M[delta]); } if (cnt) { cout << "NIE\n"; } else { cout << res << '\n';; } 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 | #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); map<int, char> M = {{-2, 'a'}, {0, 'c'}, {2, 'g'}, {4, 'o'}}; int n; cin >> n; string s; cin >> s; int cnt = -2 * count(s.begin(), s.end(), '0') + 8*n; string res; while (n--) { int delta = clamp(cnt, -2, 4); cnt-=delta; res+=(M[delta]); } if (cnt) { cout << "NIE\n"; } else { cout << res << '\n';; } return 0; } |