#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int ones = 0; for(int i = 0; i < 8 * n; i++) { char c; cin >> c; ones += (c == '1'); } int zeros = 8 * n - ones; string ans = ""; while(zeros > 0 && ones > 0 && ans.size() < n) { int diff = ones - zeros; if(diff < 0) { ans += 'a'; ones -= 3, zeros -= 5; } else if(diff == 0) { ans += 'c'; ones -= 4, zeros -= 4; } else if(diff >= 4) { ans += 'o'; ones -= 6, zeros -= 2; } else { ans += 'g'; ones -= 5, zeros -= 3; } } cout << (ones == 0 && zeros == 0 && ans.size() == n ? ans : "NIE") << "\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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int ones = 0; for(int i = 0; i < 8 * n; i++) { char c; cin >> c; ones += (c == '1'); } int zeros = 8 * n - ones; string ans = ""; while(zeros > 0 && ones > 0 && ans.size() < n) { int diff = ones - zeros; if(diff < 0) { ans += 'a'; ones -= 3, zeros -= 5; } else if(diff == 0) { ans += 'c'; ones -= 4, zeros -= 4; } else if(diff >= 4) { ans += 'o'; ones -= 6, zeros -= 2; } else { ans += 'g'; ones -= 5, zeros -= 3; } } cout << (ones == 0 && zeros == 0 && ans.size() == n ? ans : "NIE") << "\n"; return 0; } |