#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); char c[7]; for (char x='a'; x<='z'; ++x) { c[__builtin_popcount((int)(x))] = x; } int n; cin>>n; string s; cin>>s; int a=0; for (auto u : s) { if (u == '1') ++a; } if (a < 3*n) { cout<<"NIE\n"; } else { int x[n]; fill(x, x+n, 3); int cst = 3*n, i=0; while (cst < a && i < n) { if (x[i] == 6) ++i; else { ++x[i], ++cst; } } if (cst == a) { string ans; for (int i=0; i<n; ++i) ans += c[x[i]]; cout<<ans<<"\n"; } else { cout<<"NIE\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 43 44 45 46 47 48 49 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); char c[7]; for (char x='a'; x<='z'; ++x) { c[__builtin_popcount((int)(x))] = x; } int n; cin>>n; string s; cin>>s; int a=0; for (auto u : s) { if (u == '1') ++a; } if (a < 3*n) { cout<<"NIE\n"; } else { int x[n]; fill(x, x+n, 3); int cst = 3*n, i=0; while (cst < a && i < n) { if (x[i] == 6) ++i; else { ++x[i], ++cst; } } if (cst == a) { string ans; for (int i=0; i<n; ++i) ans += c[x[i]]; cout<<ans<<"\n"; } else { cout<<"NIE\n"; } } } |