#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
string a;
cin>>n>>a;
string b;
b.resize(n);
int ile0=-2*n, ile1=-2*n;
for(int i=0; i<8*n; i++){
if(a[i]=='0'){
ile0++;
}
else{
ile1++;
}
}
if(ile0<0||ile1<=0||ile1>4*n){
cout<<"NIE";
return 0;
}
int x=4;
for(int i=1; i<n; i++){
while(x!=0&&ile1-x<n-i){
x--;
}
if(x==0){
cout<<"NIE";
return 0;
}
ile1-=x;
if(x==1){
b[i-1]='a';
}
if(x==2){
b[i-1]='c';
}
if(x==3){
b[i-1]='g';
}
if(x==4){
b[i-1]='o';
}
}
if(ile1==0){
cout<<"NIE";
return 0;
}
if(ile1==1){
b[n-1]='a';
}
if(ile1==2){
b[n-1]='c';
}
if(ile1==3){
b[n-1]='g';
}
if(ile1==4){
b[n-1]='o';
}
cout<<b;
}
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 55 56 57 58 59 60 61 62 63 64 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; string a; cin>>n>>a; string b; b.resize(n); int ile0=-2*n, ile1=-2*n; for(int i=0; i<8*n; i++){ if(a[i]=='0'){ ile0++; } else{ ile1++; } } if(ile0<0||ile1<=0||ile1>4*n){ cout<<"NIE"; return 0; } int x=4; for(int i=1; i<n; i++){ while(x!=0&&ile1-x<n-i){ x--; } if(x==0){ cout<<"NIE"; return 0; } ile1-=x; if(x==1){ b[i-1]='a'; } if(x==2){ b[i-1]='c'; } if(x==3){ b[i-1]='g'; } if(x==4){ b[i-1]='o'; } } if(ile1==0){ cout<<"NIE"; return 0; } if(ile1==1){ b[n-1]='a'; } if(ile1==2){ b[n-1]='c'; } if(ile1==3){ b[n-1]='g'; } if(ile1==4){ b[n-1]='o'; } cout<<b; } |
English