#include <bits/stdc++.h>
using namespace std;
int n, a, b, cnt;
string s, res;
int p[17]; ///3 - a, 4 - c, 5 - g, 6 - o;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for(int i = 0; i < n * 8; i++){
if(s[i] == '1') cnt++;
}
//cout << cnt;
if(cnt < 3 * n || cnt > 6 * n){
cout << "NIE";
return 0;
}
for(int i = 1; i <= n; i++){
if(cnt >= (n - i) * 3 + 6){
res += 'o';
cnt -= 6;
}
else if(cnt == (n - i) * 3 + 5){
res += 'g';
cnt -= 5;
}
else if(cnt == (n - i) * 3 + 4){
res += 'c';
cnt -= 4;
}
else if(cnt == (n - i) * 3 + 3){
res += 'a';
cnt -= 3;
}
}
cout << res;
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 | #include <bits/stdc++.h> using namespace std; int n, a, b, cnt; string s, res; int p[17]; ///3 - a, 4 - c, 5 - g, 6 - o; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; for(int i = 0; i < n * 8; i++){ if(s[i] == '1') cnt++; } //cout << cnt; if(cnt < 3 * n || cnt > 6 * n){ cout << "NIE"; return 0; } for(int i = 1; i <= n; i++){ if(cnt >= (n - i) * 3 + 6){ res += 'o'; cnt -= 6; } else if(cnt == (n - i) * 3 + 5){ res += 'g'; cnt -= 5; } else if(cnt == (n - i) * 3 + 4){ res += 'c'; cnt -= 4; } else if(cnt == (n - i) * 3 + 3){ res += 'a'; cnt -= 3; } } cout << res; return 0; } |
English