//============================================================================ // Name : 2c-zak.cpp //============================================================================ #include <string> #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); string word; const char letters[] = { 'a', 'c', 'g', 'o' }; int n; cin >> n; cin >> word; int counter[2] = { 0 }; for (char const &c : word) { counter[c - '0']++; } if (counter[1] < 3 * n || counter[1] > 6 * n) { cout << "NIE" << endl; } else { int letter_index = counter[1] / n - 3; char letter = letters[letter_index]; int i = 0; for (; i < n - counter[1] % n; i++) { cout << letter; } letter = letters[++letter_index]; for (; i < n; i++) { cout << letter; } } 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 | //============================================================================ // Name : 2c-zak.cpp //============================================================================ #include <string> #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); string word; const char letters[] = { 'a', 'c', 'g', 'o' }; int n; cin >> n; cin >> word; int counter[2] = { 0 }; for (char const &c : word) { counter[c - '0']++; } if (counter[1] < 3 * n || counter[1] > 6 * n) { cout << "NIE" << endl; } else { int letter_index = counter[1] / n - 3; char letter = letters[letter_index]; int i = 0; for (; i < n - counter[1] % n; i++) { cout << letter; } letter = letters[++letter_index]; for (; i < n; i++) { cout << letter; } } return 0; } |