#define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; int main() { int n, ones = 0; char a; char letters[8] = { '0','0','0','p','c','m','o' }; cin >> n; for (int i = 0; i < 8*n; i++) { cin >> a; ones += a - '0'; } int zeros = 8 * n - ones; int diff = ones - zeros; //cout << "diff=" << diff << '\n'; if (diff > 4 * n || diff < -2 * n){ cout << "NIE" << '\n'; return 0; } else { int i = 0; if (diff > 0 && diff % 4 == 2) { cout << letters[5]; diff -= 2; i++; } while (diff > 0) { cout << letters[6]; diff -= 4; i++; } while (diff < 0) { cout << letters[3]; diff += 2; i++; } while (i < n) { cout << letters[4]; 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 | #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; int main() { int n, ones = 0; char a; char letters[8] = { '0','0','0','p','c','m','o' }; cin >> n; for (int i = 0; i < 8*n; i++) { cin >> a; ones += a - '0'; } int zeros = 8 * n - ones; int diff = ones - zeros; //cout << "diff=" << diff << '\n'; if (diff > 4 * n || diff < -2 * n){ cout << "NIE" << '\n'; return 0; } else { int i = 0; if (diff > 0 && diff % 4 == 2) { cout << letters[5]; diff -= 2; i++; } while (diff > 0) { cout << letters[6]; diff -= 4; i++; } while (diff < 0) { cout << letters[3]; diff += 2; i++; } while (i < n) { cout << letters[4]; i++; } } return 0; } |