#include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); int N; cin >> N; int cnt1 = 0; for (int i = 0; i < 8*N; i++) { char c; cin >> c; if (c == '1') cnt1++; } if (cnt1 < 3*N || cnt1 > 6*N) { cout << "NIE"; } else { cnt1 -= 2*N; for (int i = 0; i < N; i++) { int m = min(4, cnt1 - (N-i-1)); char c; switch (m) { case 1: c = 'a'; break; case 2: c = 'c'; break; case 3: c = 'g'; break; case 4: c = 'o'; break; } cout << c; cnt1 -= m; } } cout << endl; 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 40 41 | #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); int N; cin >> N; int cnt1 = 0; for (int i = 0; i < 8*N; i++) { char c; cin >> c; if (c == '1') cnt1++; } if (cnt1 < 3*N || cnt1 > 6*N) { cout << "NIE"; } else { cnt1 -= 2*N; for (int i = 0; i < N; i++) { int m = min(4, cnt1 - (N-i-1)); char c; switch (m) { case 1: c = 'a'; break; case 2: c = 'c'; break; case 3: c = 'g'; break; case 4: c = 'o'; break; } cout << c; cnt1 -= m; } } cout << endl; return 0; } |