#include <iostream> #include <map> using namespace std; int n, zeros; char a; map<int, char> mapping {{5, 'a'}, {4, 'c'}, {3, 'g'}, {2, 'o'},}; int main() { ios::sync_with_stdio(false); cin >> n; for(int i = 0; i < n * 8; i++) { cin >> a; if (a == '0') { zeros++; } } if ((zeros/n < 2) || (n * 5 < zeros)) { cout << "NIE"; return 0; } string out = ""; for(int i = n-1; i >= 0; i--) { int max_zeros = min(zeros - i * 2, 5); zeros -= max_zeros; out += mapping[max_zeros]; } cout << out; 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 | #include <iostream> #include <map> using namespace std; int n, zeros; char a; map<int, char> mapping {{5, 'a'}, {4, 'c'}, {3, 'g'}, {2, 'o'},}; int main() { ios::sync_with_stdio(false); cin >> n; for(int i = 0; i < n * 8; i++) { cin >> a; if (a == '0') { zeros++; } } if ((zeros/n < 2) || (n * 5 < zeros)) { cout << "NIE"; return 0; } string out = ""; for(int i = n-1; i >= 0; i--) { int max_zeros = min(zeros - i * 2, 5); zeros -= max_zeros; out += mapping[max_zeros]; } cout << out; return 0; } |