#include <bits/stdc++.h> using namespace std; template<class T, class Y> ostream& operator<<(ostream& out, const pair<T,Y>& p) {out << p.first << ": " << p.second; return out;} template<class T> ostream& __print(ostream& out, string st, string en, string sep, T con) {out << st;typename T::size_type i=0; for (auto it=con.begin(); it!=con.end(); ++it, i++) {out << *it << (i<con.size()-1 ? sep : "");} out << en; return out;} #define register_print1(a, b, c, d) template <class T> \ ostream& operator<<(ostream& out, const a<T>& con) \ {return __print(out, b, c, d, con);} #define register_print2(a, b, c, d) template <class T, class Y> \ ostream& operator<<(ostream& out, const a<T, Y>& con) \ {return __print(out, b, c, d, con);} register_print1(vector, "[", "]", ", ") register_print1(set, "{", "}", ", ") register_print1(unordered_set, "{", "}", ", ") register_print2(map, "{", "}", ", ") register_print2(unordered_map, "{", "}", ", ") void solve() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int cnt = 0; for (int i=0; i<8*n; i++) { cnt += (s[i] == '1'); } if (cnt < 3*n || cnt > 6*n) { cout << "NIE\n"; return; } string out; for (int i=0; i<n; i++) { out += "a"; cnt -= 3; } int i = 0; while (cnt) { if (cnt >= 3) { out[i] = 'o'; cnt -= 3; } else if (cnt == 2) { out[i] = 'n'; cnt -= 2; } else if (cnt == 1) { out[i] = 'c'; cnt -= 1; } i++; } cout << out << "\n"; } int main() {solve();}
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include <bits/stdc++.h> using namespace std; template<class T, class Y> ostream& operator<<(ostream& out, const pair<T,Y>& p) {out << p.first << ": " << p.second; return out;} template<class T> ostream& __print(ostream& out, string st, string en, string sep, T con) {out << st;typename T::size_type i=0; for (auto it=con.begin(); it!=con.end(); ++it, i++) {out << *it << (i<con.size()-1 ? sep : "");} out << en; return out;} #define register_print1(a, b, c, d) template <class T> \ ostream& operator<<(ostream& out, const a<T>& con) \ {return __print(out, b, c, d, con);} #define register_print2(a, b, c, d) template <class T, class Y> \ ostream& operator<<(ostream& out, const a<T, Y>& con) \ {return __print(out, b, c, d, con);} register_print1(vector, "[", "]", ", ") register_print1(set, "{", "}", ", ") register_print1(unordered_set, "{", "}", ", ") register_print2(map, "{", "}", ", ") register_print2(unordered_map, "{", "}", ", ") void solve() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int cnt = 0; for (int i=0; i<8*n; i++) { cnt += (s[i] == '1'); } if (cnt < 3*n || cnt > 6*n) { cout << "NIE\n"; return; } string out; for (int i=0; i<n; i++) { out += "a"; cnt -= 3; } int i = 0; while (cnt) { if (cnt >= 3) { out[i] = 'o'; cnt -= 3; } else if (cnt == 2) { out[i] = 'n'; cnt -= 2; } else if (cnt == 1) { out[i] = 'c'; cnt -= 1; } i++; } cout << out << "\n"; } int main() {solve();} |