#include <iostream> using namespace std; int main() { char three_ones = 'a'; char four_ones = 'e'; char five_ones = 'k'; char six_ones = 'w'; int n; cin >> n; int one_count = 0; for (int i = 0; i < 8 * n; ++i) { char d; cin >> d; one_count += d - '0'; } if (one_count < 3 * n || one_count > 6 * n) { cout << "NIE"; exit(0); } int three_count = n; one_count -= 3 * n; int six_count = 0; while(one_count >= 3) { six_count++; one_count -= 3; three_count -= 1; } for (int i = 0; i < three_count - (one_count == 0 ? 0 : 1); ++i) { cout << three_ones; } for (int i = 0; i < six_count; ++i) { cout << six_ones; } if(one_count == 1) { cout << four_ones; } else if(one_count == 2) { cout << five_ones; } 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 | #include <iostream> using namespace std; int main() { char three_ones = 'a'; char four_ones = 'e'; char five_ones = 'k'; char six_ones = 'w'; int n; cin >> n; int one_count = 0; for (int i = 0; i < 8 * n; ++i) { char d; cin >> d; one_count += d - '0'; } if (one_count < 3 * n || one_count > 6 * n) { cout << "NIE"; exit(0); } int three_count = n; one_count -= 3 * n; int six_count = 0; while(one_count >= 3) { six_count++; one_count -= 3; three_count -= 1; } for (int i = 0; i < three_count - (one_count == 0 ? 0 : 1); ++i) { cout << three_ones; } for (int i = 0; i < six_count; ++i) { cout << six_ones; } if(one_count == 1) { cout << four_ones; } else if(one_count == 2) { cout << five_ones; } return 0; } |