#include <iostream> #include <cstring> #include <cmath> using namespace std; int main(){ int n; string s; cin >> n; cin >> s; int c = 0; for (int i = 0; i < 8 * n; i++){ if (s[i] == '1'){ c++; } } double ratio = (double)c / n; double w = ratio - (int)ratio; w *= n; int la = round(w); if ((ratio < 3) || (ratio > 6)){ cout << "NIE\n"; return 0; } char let[8]; let[3] = 'a'; let[4] = 'c'; let[5] = 'g'; let[6] = 'w'; int bits_used = 0; //cout << ratio << " " << w << " " << round(w) << " " << la << "\n"; for (int i = 0; i < la; i++){ cout << let[(int)ratio + 1]; bits_used += (int)ratio + 1; } for (int i = la; i < n - 1; i++){ cout << let[(int)(ratio)]; bits_used += (int)ratio; } if (la < n){ //cout << c << " " << bits_used << "\n"; cout << let[c - bits_used]; } }
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 | #include <iostream> #include <cstring> #include <cmath> using namespace std; int main(){ int n; string s; cin >> n; cin >> s; int c = 0; for (int i = 0; i < 8 * n; i++){ if (s[i] == '1'){ c++; } } double ratio = (double)c / n; double w = ratio - (int)ratio; w *= n; int la = round(w); if ((ratio < 3) || (ratio > 6)){ cout << "NIE\n"; return 0; } char let[8]; let[3] = 'a'; let[4] = 'c'; let[5] = 'g'; let[6] = 'w'; int bits_used = 0; //cout << ratio << " " << w << " " << round(w) << " " << la << "\n"; for (int i = 0; i < la; i++){ cout << let[(int)ratio + 1]; bits_used += (int)ratio + 1; } for (int i = la; i < n - 1; i++){ cout << let[(int)(ratio)]; bits_used += (int)ratio; } if (la < n){ //cout << c << " " << bits_used << "\n"; cout << let[c - bits_used]; } } |