#include <iostream> using namespace std; char tab[] = { 'a', 'c', 'g', 'o'}; //3, 4, 5, 6 void task(int n, int k) { if (3 * n > k || 6 * n < k) { cout << "NIE"; return; } k -= n * 3; int w = 0; while (w < n) { for (int i = 3; i >= 0; i--) { if (k >= i) { k -= i; cout << tab[i]; w++; break; } } } return; } int main() { int n; char a; int k = 0; cin >> n; for (int i = 0; i < 8 * n; i++) { cin >> a; k += a - '0'; } task(n, k); }
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 | #include <iostream> using namespace std; char tab[] = { 'a', 'c', 'g', 'o'}; //3, 4, 5, 6 void task(int n, int k) { if (3 * n > k || 6 * n < k) { cout << "NIE"; return; } k -= n * 3; int w = 0; while (w < n) { for (int i = 3; i >= 0; i--) { if (k >= i) { k -= i; cout << tab[i]; w++; break; } } } return; } int main() { int n; char a; int k = 0; cin >> n; for (int i = 0; i < 8 * n; i++) { cin >> a; k += a - '0'; } task(n, k); } |