#include <iostream>
using namespace std;
char letters[] = {'a', 'c', 'g', 'o'};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
int ones_count = 0;
cin >> n;
for (int i = 0; i < 8 * n; i++) {
char c;
cin >> c;
if (c == '1')
ones_count++;
}
if (ones_count < 3 * n || ones_count > 6 * n) {
cout << "NIE";
exit(0);
}
for (int i = n; i > 0; i--) {
for (int j = 6; j >= 3; j--) {
if (i * j <= ones_count) {
ones_count -= j;
cout << letters[j - 3];
break;
}
}
}
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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <iostream> using namespace std; char letters[] = {'a', 'c', 'g', 'o'}; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; int ones_count = 0; cin >> n; for (int i = 0; i < 8 * n; i++) { char c; cin >> c; if (c == '1') ones_count++; } if (ones_count < 3 * n || ones_count > 6 * n) { cout << "NIE"; exit(0); } for (int i = n; i > 0; i--) { for (int j = 6; j >= 3; j--) { if (i * j <= ones_count) { ones_count -= j; cout << letters[j - 3]; break; } } } return 0; } |
English