#include <iostream> using namespace std; char l1 = 'a'; char l2 = 'c'; char l3 = 'g'; char l4 = 'o'; int main() { int n; char c; cin >> n; int totalj = 0; int minj = n * 3; int maxj = n * 6; for (int i = 0; i < n; ++i) { for (int j = 0; j < 8; ++j) { cin >> c; if (c == '1') { totalj++; } } } if (totalj < minj || totalj > maxj) { cout << "NIE" << endl; return 0; } int nadmiar = totalj - minj; // cout << "NADMIAR: " << nadmiar << endl; int leftover = n; while (nadmiar >= 3) { cout << l4; nadmiar -= 3; leftover--; } if (nadmiar == 2) { cout << l3; leftover--; } if (nadmiar == 1) { cout << l2; leftover--; } for (int i = 0; i < leftover; ++i) { cout << l1; } cout << 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 47 48 49 50 | #include <iostream> using namespace std; char l1 = 'a'; char l2 = 'c'; char l3 = 'g'; char l4 = 'o'; int main() { int n; char c; cin >> n; int totalj = 0; int minj = n * 3; int maxj = n * 6; for (int i = 0; i < n; ++i) { for (int j = 0; j < 8; ++j) { cin >> c; if (c == '1') { totalj++; } } } if (totalj < minj || totalj > maxj) { cout << "NIE" << endl; return 0; } int nadmiar = totalj - minj; // cout << "NADMIAR: " << nadmiar << endl; int leftover = n; while (nadmiar >= 3) { cout << l4; nadmiar -= 3; leftover--; } if (nadmiar == 2) { cout << l3; leftover--; } if (nadmiar == 1) { cout << l2; leftover--; } for (int i = 0; i < leftover; ++i) { cout << l1; } cout << endl; return 0; } |