#include<bits/stdc++.h>
using namespace std;
int countt(int tmp)
{
int counter = 0;
while(tmp != 0){
if(tmp & 1)
counter++;
tmp /= 2;
}
return counter;
}
void init()
{
vector<int> values;
for(int letter = 97; letter <= 122; letter++){
cout<<(char)letter<<": "<<countt(letter)<<endl;
values.push_back(countt(letter));
}
/*sort(values.begin(),values.end());
//for(auto cur : values) cout<<cur<<" ";
vector<int>::iterator it = unique(values.begin(),values.end());
for(vector<int>::iterator i = values.begin(); i < it; i++){
cout<<*i<<" ";
}*/
}
char printLetter(int bitCount)
{
switch(bitCount)
{
case 3:
return 'a';
case 4:
return 'c';
case 5:
return 'k';
case 6:
return 'w';
default:
return '0';
}
}
bool chceck(int sum, int n, int mod)
{
if(sum % mod == 0 && sum / mod == n){
while(sum != 0){
cout<<printLetter(mod);
sum -= mod;
}
return true;
}
return false;
}
bool cout_a_b(int x, int y, int z, int n, int & a, int & b)
{
if((n-y-z + 4*n) % 2 == 1)
return false;
b = (n-y-z)/2;
a = n - y - z - 2*b;
return true;
}
int main()
{
//warunki
//bitSum = a * 3 + b * 4 + c * 5 + d * 6 = a * 3 + 2b * 2 + c * 5 + 2d * 3 = (a+2d) * 3 + 2b * 2 + c * 5
//a + b + c + d = n
//init();
//cout<<endl;
int n;
string data;
cin>>n;
cin>>data;
int bitSum= 0;
for(int i = 0; i < data.size(); i++){
if(data[i] == '1')
bitSum++;
}
/*int try_nb[4] = {3,4,5,6};
for(int i = 0; i < 4; i++){
if(chceck(bitSum,n,try_nb[i]))
return 0;
}*/
int w,x;
for(int z = 0; z <= n; z++){
for(int y = 0; y <= n; y++){
x = bitSum - 3*n - 2*y - 3*z;
if( x>=0 ){
w = n - x - y - z;
if(w >= 0){
for(int i = 0; i < w; i++)cout<<printLetter(3);
for(int i = 0; i < x; i++)cout<<printLetter(4);
for(int i = 0; i < y; i++)cout<<printLetter(5);
for(int i = 0; i < z; i++)cout<<printLetter(6);
cout<<endl;
return 0;
}
}
}
}
cout<<"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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #include<bits/stdc++.h> using namespace std; int countt(int tmp) { int counter = 0; while(tmp != 0){ if(tmp & 1) counter++; tmp /= 2; } return counter; } void init() { vector<int> values; for(int letter = 97; letter <= 122; letter++){ cout<<(char)letter<<": "<<countt(letter)<<endl; values.push_back(countt(letter)); } /*sort(values.begin(),values.end()); //for(auto cur : values) cout<<cur<<" "; vector<int>::iterator it = unique(values.begin(),values.end()); for(vector<int>::iterator i = values.begin(); i < it; i++){ cout<<*i<<" "; }*/ } char printLetter(int bitCount) { switch(bitCount) { case 3: return 'a'; case 4: return 'c'; case 5: return 'k'; case 6: return 'w'; default: return '0'; } } bool chceck(int sum, int n, int mod) { if(sum % mod == 0 && sum / mod == n){ while(sum != 0){ cout<<printLetter(mod); sum -= mod; } return true; } return false; } bool cout_a_b(int x, int y, int z, int n, int & a, int & b) { if((n-y-z + 4*n) % 2 == 1) return false; b = (n-y-z)/2; a = n - y - z - 2*b; return true; } int main() { //warunki //bitSum = a * 3 + b * 4 + c * 5 + d * 6 = a * 3 + 2b * 2 + c * 5 + 2d * 3 = (a+2d) * 3 + 2b * 2 + c * 5 //a + b + c + d = n //init(); //cout<<endl; int n; string data; cin>>n; cin>>data; int bitSum= 0; for(int i = 0; i < data.size(); i++){ if(data[i] == '1') bitSum++; } /*int try_nb[4] = {3,4,5,6}; for(int i = 0; i < 4; i++){ if(chceck(bitSum,n,try_nb[i])) return 0; }*/ int w,x; for(int z = 0; z <= n; z++){ for(int y = 0; y <= n; y++){ x = bitSum - 3*n - 2*y - 3*z; if( x>=0 ){ w = n - x - y - z; if(w >= 0){ for(int i = 0; i < w; i++)cout<<printLetter(3); for(int i = 0; i < x; i++)cout<<printLetter(4); for(int i = 0; i < y; i++)cout<<printLetter(5); for(int i = 0; i < z; i++)cout<<printLetter(6); cout<<endl; return 0; } } } } cout<<"NIE\n"; return 0; } |
English