#include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <algorithm> #include <cstring> #include <ctime> #include <cassert> using namespace std; map<int, char> letter{{3, 'a'}, {4, 'c'}, {5, 'g'}, {6, 'o'}}; vector<int> jumps = {3, 4, 5, 6}; int main() { int n; cin >> n; string s; cin >> s; int m = 0; for (int i = 0; i < 8*n; ++i) { m += s[i] == '1'; } if (3*n <= m && m <= 6*n) { string res; while (n > 0) { for (auto j : jumps) { if (3*(n-1) <= m-j && m-j <= 6*(n-1)) { res += letter[j]; m -= j; n -= 1; break; } } } cout << res << endl; } else { cout << "NIE" << 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <algorithm> #include <cstring> #include <ctime> #include <cassert> using namespace std; map<int, char> letter{{3, 'a'}, {4, 'c'}, {5, 'g'}, {6, 'o'}}; vector<int> jumps = {3, 4, 5, 6}; int main() { int n; cin >> n; string s; cin >> s; int m = 0; for (int i = 0; i < 8*n; ++i) { m += s[i] == '1'; } if (3*n <= m && m <= 6*n) { string res; while (n > 0) { for (auto j : jumps) { if (3*(n-1) <= m-j && m-j <= 6*(n-1)) { res += letter[j]; m -= j; n -= 1; break; } } } cout << res << endl; } else { cout << "NIE" << endl; } return 0; } |