#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string c;
cin >> c;
int jeden = 0;
for(int i = 0; i < n*8; i++){
if(c[i] == '1') jeden++;
}
string s;
if(jeden < n*3 || jeden > n*6){
cout << "NIE";
return 0;
}
int wynik[n];
int suma = 0;
for(int i = 0; i < n; i++){
wynik[i] = 6;
suma+=6;
}
int j = n-1;
while(suma != jeden){
if(wynik[j] == 3) j--;
wynik[j]--;
suma--;
}
for(int i = 0; i < n; i++){
switch(wynik[i]){
case 3:
cout << 'a';
break;
case 4:
cout << 'c';
break;
case 5:
cout << 'n';
break;
case 6:
cout << 'w';
break;
}
}
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 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string c; cin >> c; int jeden = 0; for(int i = 0; i < n*8; i++){ if(c[i] == '1') jeden++; } string s; if(jeden < n*3 || jeden > n*6){ cout << "NIE"; return 0; } int wynik[n]; int suma = 0; for(int i = 0; i < n; i++){ wynik[i] = 6; suma+=6; } int j = n-1; while(suma != jeden){ if(wynik[j] == 3) j--; wynik[j]--; suma--; } for(int i = 0; i < n; i++){ switch(wynik[i]){ case 3: cout << 'a'; break; case 4: cout << 'c'; break; case 5: cout << 'n'; break; case 6: cout << 'w'; break; } } return 0; } |
English