#include <bits/stdc++.h> using namespace std; typedef string string; string solve(int n, int lic){ if(lic < 3*n || lic > 6*n) return "NIE"; string ans = ""; if(lic % 3 == 1) { ans += 'c'; lic -= 4; } else if(lic % 3 == 2) { ans += 'g'; lic -= 5; } else if(lic == 6*n) { ans += 'o'; lic -= 6; } else { ans += 'a'; lic -= 3; } lic /= 3; n--; lic -= n; for(int i = 0; i < lic; i++){ ans += 'o'; } for(int i = lic; i < n; i++){ ans += 'a'; } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, lic = 0; cin >> n; string s; cin >> s; for(int i = 0; i < 8*n; i++){ if(s[i] == '1') lic++; } if(lic < 3*n || lic > 6*n) cout << "NIE"; else cout << solve(n, lic); 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 48 49 50 51 52 53 54 | #include <bits/stdc++.h> using namespace std; typedef string string; string solve(int n, int lic){ if(lic < 3*n || lic > 6*n) return "NIE"; string ans = ""; if(lic % 3 == 1) { ans += 'c'; lic -= 4; } else if(lic % 3 == 2) { ans += 'g'; lic -= 5; } else if(lic == 6*n) { ans += 'o'; lic -= 6; } else { ans += 'a'; lic -= 3; } lic /= 3; n--; lic -= n; for(int i = 0; i < lic; i++){ ans += 'o'; } for(int i = lic; i < n; i++){ ans += 'a'; } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, lic = 0; cin >> n; string s; cin >> s; for(int i = 0; i < 8*n; i++){ if(s[i] == '1') lic++; } if(lic < 3*n || lic > 6*n) cout << "NIE"; else cout << solve(n, lic); return 0; } |