#include <bits/stdc++.h> using namespace std; constexpr int MIN_PER = 3, MAX_PER = 6; char OF_PER[MAX_PER - MIN_PER + 1] = {'a', 'c', 'g', 'o'}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); size_t n; string S; cin >> n >> S; int x = count(S.begin(), S.end(), '1'); x -= n * MIN_PER; if(x < 0 or x > (MAX_PER - MIN_PER) * (int)n) { cout << "NIE" << endl; return 0; } string R(n, '?'); for(size_t i = 0; i < n; i++) { int y = min(x, MAX_PER - MIN_PER); R[i] = OF_PER[y]; x -= y; } cout << R << endl; }
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 | #include <bits/stdc++.h> using namespace std; constexpr int MIN_PER = 3, MAX_PER = 6; char OF_PER[MAX_PER - MIN_PER + 1] = {'a', 'c', 'g', 'o'}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); size_t n; string S; cin >> n >> S; int x = count(S.begin(), S.end(), '1'); x -= n * MIN_PER; if(x < 0 or x > (MAX_PER - MIN_PER) * (int)n) { cout << "NIE" << endl; return 0; } string R(n, '?'); for(size_t i = 0; i < n; i++) { int y = min(x, MAX_PER - MIN_PER); R[i] = OF_PER[y]; x -= y; } cout << R << endl; } |