#include <iostream> #include <set> #include <map> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; string s, result = ""; cin >> s; int cnt[2] = {0, 0}; for(char c : s) cnt[c - '0']++; int x = cnt[0] - cnt[1], turns = 0; for(int i = 0; i < n; i++) { if(x == 0) { result += 'x'; } else if(x > 0) { result += 'p'; x -= 2; } else if(x <= -4) { result += 'w'; x += 4; } else { result += 'z'; x += 2; } } cout << (x == 0 ? result : "NIE\n") << '\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 | #include <iostream> #include <set> #include <map> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; string s, result = ""; cin >> s; int cnt[2] = {0, 0}; for(char c : s) cnt[c - '0']++; int x = cnt[0] - cnt[1], turns = 0; for(int i = 0; i < n; i++) { if(x == 0) { result += 'x'; } else if(x > 0) { result += 'p'; x -= 2; } else if(x <= -4) { result += 'w'; x += 4; } else { result += 'z'; x += 2; } } cout << (x == 0 ? result : "NIE\n") << '\n'; return 0; } |