#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n, MAX = 100001;
char b[8*MAX] = {0,}, r[MAX] = {0,};
cin >> n >> b;
int ones = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 8; j++) {
if (b[8*i + j] == '1') {
ones++;
}
}
}
for (int i = 0; i < n; i++) {
double avg = (double) ones / (n - i);
int rounded = round(avg);
switch (rounded) {
case 3: r[i] = 'a'; break;
case 4: r[i] = 'c'; break;
case 5: r[i] = 'g'; break;
case 6: r[i] = 'o'; break;
default: cout << "NIE" << endl; return 0;
}
ones -= rounded;
}
cout << r << 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 | #include <iostream> #include <math.h> using namespace std; int main() { int n, MAX = 100001; char b[8*MAX] = {0,}, r[MAX] = {0,}; cin >> n >> b; int ones = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 8; j++) { if (b[8*i + j] == '1') { ones++; } } } for (int i = 0; i < n; i++) { double avg = (double) ones / (n - i); int rounded = round(avg); switch (rounded) { case 3: r[i] = 'a'; break; case 4: r[i] = 'c'; break; case 5: r[i] = 'g'; break; case 6: r[i] = 'o'; break; default: cout << "NIE" << endl; return 0; } ones -= rounded; } cout << r << endl; return 0; } |
English