#include<iostream> #include<vector> using namespace std; char tab[7] = { 'x', 'x', 'x', 'a', 'c', 'g', 'o' }; int main() { int n; string s; cin >> n >> s; int ones = 0; for (char x : s) ones += int(x == '1'); if (ones < 3 * n or ones > 6 * n) { cout << "NIE\n"; return 0; } int value = ones / n; int add_one = ones - (n * value); for (int i = 0; i < n; i++) { if (i < add_one) cout << tab[value + 1]; else cout << tab[value]; } cout << "\n"; }
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 | #include<iostream> #include<vector> using namespace std; char tab[7] = { 'x', 'x', 'x', 'a', 'c', 'g', 'o' }; int main() { int n; string s; cin >> n >> s; int ones = 0; for (char x : s) ones += int(x == '1'); if (ones < 3 * n or ones > 6 * n) { cout << "NIE\n"; return 0; } int value = ones / n; int add_one = ones - (n * value); for (int i = 0; i < n; i++) { if (i < add_one) cout << tab[value + 1]; else cout << tab[value]; } cout << "\n"; } |