#include <bits/stdc++.h> using namespace std; int main() { int n; char c; int num[2] = {0, 0}; cin >> n; for (int i = 0; i < 8*n; i++){ cin >> c; if (c == '0') num[0]++; else num[1]++; } int bilans = num[0] - num[1]; int num_a = 0, num_w = 0, num_n = 0, num_e = 0; if (bilans % 2 == 1) {cout << "NIE"; return 0;} if (bilans > 0) num_a = bilans / 2; else if (bilans < 0){ num_w = -bilans/4; num_n = (-bilans % 4)/2; } num_e = (num[0] + num[1])/8 - num_a - num_w - num_n; if (num_e < 0) {cout << "NIE"; return 0;} for (int i = 0; i < num_a; i++) cout << "a"; for (int i = 0; i < num_w; i++) cout << "w"; for (int i = 0; i < num_n; i++) cout << "n"; for (int i = 0; i < num_e; i++) cout << "e"; }
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 | #include <bits/stdc++.h> using namespace std; int main() { int n; char c; int num[2] = {0, 0}; cin >> n; for (int i = 0; i < 8*n; i++){ cin >> c; if (c == '0') num[0]++; else num[1]++; } int bilans = num[0] - num[1]; int num_a = 0, num_w = 0, num_n = 0, num_e = 0; if (bilans % 2 == 1) {cout << "NIE"; return 0;} if (bilans > 0) num_a = bilans / 2; else if (bilans < 0){ num_w = -bilans/4; num_n = (-bilans % 4)/2; } num_e = (num[0] + num[1])/8 - num_a - num_w - num_n; if (num_e < 0) {cout << "NIE"; return 0;} for (int i = 0; i < num_a; i++) cout << "a"; for (int i = 0; i < num_w; i++) cout << "w"; for (int i = 0; i < num_n; i++) cout << "n"; for (int i = 0; i < num_e; i++) cout << "e"; } |