#include <bits/stdc++.h> using namespace std; using ll = long long; string solve(int n, int zero, int one) { zero -= 2*n; one -= 3*n; if (zero < 0 || one < 0) { return "NIE"; } return string(zero / 3, 'p') + string(one / 3, 'w') + (zero % 3 == 1 ? "u" : one % 3 == 1 ? "t" : ""); } int main() { int n; cin >> n; string s; cin >> s; int zero = 0, one = 0; for (auto c : s) { if (c == '0') { zero++; } else { one++; } } cout << solve(n, zero, one) << endl; }
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; using ll = long long; string solve(int n, int zero, int one) { zero -= 2*n; one -= 3*n; if (zero < 0 || one < 0) { return "NIE"; } return string(zero / 3, 'p') + string(one / 3, 'w') + (zero % 3 == 1 ? "u" : one % 3 == 1 ? "t" : ""); } int main() { int n; cin >> n; string s; cin >> s; int zero = 0, one = 0; for (auto c : s) { if (c == '0') { zero++; } else { one++; } } cout << solve(n, zero, one) << endl; } |