#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; string input; cin >> input; int onesCount = 0; for(int i = 0; i < input.size(); ++i){ if(input[i] == '1'){ ++onesCount; } } if(onesCount < n * 3 || onesCount > n * 6){ cout << "NIE\n"; return 0; } string s(n, 'a'); onesCount -= n * 3; int iter = 0; while(onesCount >= 3){ s[iter] = 'w'; onesCount -= 3; ++iter; } if(onesCount == 2){ s[iter] = 'v'; ++iter; onesCount -= 2; } if(onesCount == 1){ s[iter] = 't'; ++iter; onesCount -= 1; } cout << s << '\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 | #include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; string input; cin >> input; int onesCount = 0; for(int i = 0; i < input.size(); ++i){ if(input[i] == '1'){ ++onesCount; } } if(onesCount < n * 3 || onesCount > n * 6){ cout << "NIE\n"; return 0; } string s(n, 'a'); onesCount -= n * 3; int iter = 0; while(onesCount >= 3){ s[iter] = 'w'; onesCount -= 3; ++iter; } if(onesCount == 2){ s[iter] = 'v'; ++iter; onesCount -= 2; } if(onesCount == 1){ s[iter] = 't'; ++iter; onesCount -= 1; } cout << s << '\n'; return 0; } |