#include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int c0 = 0; int c1 = 0; char c = ' '; for (int i = 0; i < 8 * n; i++) { cin >> c; if (c == '0') { c0++; } else { c1++; } } if ((c1 - c0) % 2 != 0) { cout << "NIE"; return 0; } //cout << "c1: " << c1 << ", c0: " << c0 << endl; int x1 = 0; int x2 = 0; int x3 = 0; if (c1 - c0 >= 4) { x1 = (c1 - c0) / 4; } if (c1 - c0 >= 2 && (c1 - c0) % 4 == 2) { x2 = 1; } if (c0 - c1 >= 2) { x3 = (c0 - c1) / 2; } //cout << x1 << ", " << x2 << ", " << x3 << endl; int a = c1 - 6 * x1 - 5 * x2 - 3 * x3; int b = c0 - 2 * x1 - 3 * x2 - 5 * x3; //cout << a << ", " << b << endl; if (a < 0 || b < 0 || a != b || a % 4 != 0) { cout << "NIE"; return 0; } for (int i = 0; i < x1; i++) { cout << 'w'; } for (int i = 0; i < x2; i++) { cout << 'y'; } for (int i = 0; i < x3; i++) { cout << 'a'; } for (int i = a; i > 0; i-=4) { cout << 'i'; } 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int c0 = 0; int c1 = 0; char c = ' '; for (int i = 0; i < 8 * n; i++) { cin >> c; if (c == '0') { c0++; } else { c1++; } } if ((c1 - c0) % 2 != 0) { cout << "NIE"; return 0; } //cout << "c1: " << c1 << ", c0: " << c0 << endl; int x1 = 0; int x2 = 0; int x3 = 0; if (c1 - c0 >= 4) { x1 = (c1 - c0) / 4; } if (c1 - c0 >= 2 && (c1 - c0) % 4 == 2) { x2 = 1; } if (c0 - c1 >= 2) { x3 = (c0 - c1) / 2; } //cout << x1 << ", " << x2 << ", " << x3 << endl; int a = c1 - 6 * x1 - 5 * x2 - 3 * x3; int b = c0 - 2 * x1 - 3 * x2 - 5 * x3; //cout << a << ", " << b << endl; if (a < 0 || b < 0 || a != b || a % 4 != 0) { cout << "NIE"; return 0; } for (int i = 0; i < x1; i++) { cout << 'w'; } for (int i = 0; i < x2; i++) { cout << 'y'; } for (int i = 0; i < x3; i++) { cout << 'a'; } for (int i = a; i > 0; i-=4) { cout << 'i'; } return 0; } |