#include <iostream> int main() { int n; std::cin >> n; std::string s; std::cin >> s; int zeroes = 0; int ones = 0; for (auto c: s) { if (c == '0') { ++zeroes; } else { ++ones; } } if ((zeroes - ones)&1) { puts("NIE\n"); return 0; } if (zeroes > ones) { if ((zeroes - ones) / 2 > n) { puts("NIE\n"); } else { std::string result((zeroes - ones) / 2, 'a'); result += std::string(n - result.length(), 'c'); std::cout << result << '\n'; } } else { if ((ones - zeroes + 2) / 4 > n) { puts("NIE\n"); } else { std::string result((ones - zeroes) / 4, 'w'); if ((ones - zeroes) % 4 == 2) { result += 'z'; } result += std::string(n - result.length(), 'c'); std::cout << result << '\n'; } } 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 | #include <iostream> int main() { int n; std::cin >> n; std::string s; std::cin >> s; int zeroes = 0; int ones = 0; for (auto c: s) { if (c == '0') { ++zeroes; } else { ++ones; } } if ((zeroes - ones)&1) { puts("NIE\n"); return 0; } if (zeroes > ones) { if ((zeroes - ones) / 2 > n) { puts("NIE\n"); } else { std::string result((zeroes - ones) / 2, 'a'); result += std::string(n - result.length(), 'c'); std::cout << result << '\n'; } } else { if ((ones - zeroes + 2) / 4 > n) { puts("NIE\n"); } else { std::string result((ones - zeroes) / 4, 'w'); if ((ones - zeroes) % 4 == 2) { result += 'z'; } result += std::string(n - result.length(), 'c'); std::cout << result << '\n'; } } return 0; } |