#include <iostream> #include <vector> using namespace std; constexpr char L[5] = { 'a', 'c', 'g', 'o' }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string S; cin >> n >> S; int zeros = -2 * n, ones = -3 * n; for (auto c : S) { if (c == '0') zeros++; else ones++; } if (ones < 0 || zeros < 0) cout << "NIE"; else { vector<int> R(n, ones / n); for (int i = 0; i < ones % n; i++) R[i]++; for (auto r : R) cout << L[r]; } cout << '\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 | #include <iostream> #include <vector> using namespace std; constexpr char L[5] = { 'a', 'c', 'g', 'o' }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string S; cin >> n >> S; int zeros = -2 * n, ones = -3 * n; for (auto c : S) { if (c == '0') zeros++; else ones++; } if (ones < 0 || zeros < 0) cout << "NIE"; else { vector<int> R(n, ones / n); for (int i = 0; i < ones % n; i++) R[i]++; for (auto r : R) cout << L[r]; } cout << '\n'; } |