#include <iostream> #include <cmath> using namespace std; int main(){ long n,bitup=0,bitdown=0; char bit; cin>>n; for(long i=1;i<=8*n;i++){ cin >>bit; if (bit =='1') bitup++; if (bit =='0') bitdown++; } if(bitup<3*n or bitup>6*n) { cout <<"NIE" << endl; return 0; } int x = (int)((6*n - bitup)/3); int y = (int)((6*n-bitup -3*x)/2); int z = (int)((6*n-bitup -3*x -2*y)); for(long k=1;k<=x;k++) {cout << 'a';} for(long k=1;k<=y;k++) {cout << 'c';} for(long k=1;k<=z;k++) {cout << 'g';} for(long k=1;k<=n-x-y-z;k++) {cout << 'o';} cout<<endl; 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 | #include <iostream> #include <cmath> using namespace std; int main(){ long n,bitup=0,bitdown=0; char bit; cin>>n; for(long i=1;i<=8*n;i++){ cin >>bit; if (bit =='1') bitup++; if (bit =='0') bitdown++; } if(bitup<3*n or bitup>6*n) { cout <<"NIE" << endl; return 0; } int x = (int)((6*n - bitup)/3); int y = (int)((6*n-bitup -3*x)/2); int z = (int)((6*n-bitup -3*x -2*y)); for(long k=1;k<=x;k++) {cout << 'a';} for(long k=1;k<=y;k++) {cout << 'c';} for(long k=1;k<=z;k++) {cout << 'g';} for(long k=1;k<=n-x-y-z;k++) {cout << 'o';} cout<<endl; return 0; } |