#include <bits/stdc++.h> using namespace std; int n, m, l1, l2, l3, l4, sum; void in() { scanf("%d\n", &n); for(int i = 0; i < n * 8; i++) { if(getchar() - '0') m++; } } void calc() { if(m - 3 * n < 0) { l1 = -1; return; } while(3 * (l4 + 1) <= m - 3 * n) l4++; while(3 * l4 + 2 * (l3 + 1) <= m - 3 * n) l3++; while(3 * l4 + 2 * l3 + (l2 + 1) <= m - 3 * n) l2++; l1 = n - l4 - l3 - l2; //cout << l1 + l2 + l3 + l4 << " " << n << endl << 3 * l1 + 4 * l2 + 5 * l3 + 6 * l4 << " " << m << endl << m - 3 * n << " " << l2 + 2 * l3 + 3 * l4 << endl; } void out() { if(l1 < 0) printf("NIE"); else { while(l1--) putchar('a'); while(l2--) putchar('c'); while(l3--) putchar('g'); while(l4--) putchar('o'); } } int main() { in(); calc(); out(); }
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 51 52 53 54 55 56 57 58 | #include <bits/stdc++.h> using namespace std; int n, m, l1, l2, l3, l4, sum; void in() { scanf("%d\n", &n); for(int i = 0; i < n * 8; i++) { if(getchar() - '0') m++; } } void calc() { if(m - 3 * n < 0) { l1 = -1; return; } while(3 * (l4 + 1) <= m - 3 * n) l4++; while(3 * l4 + 2 * (l3 + 1) <= m - 3 * n) l3++; while(3 * l4 + 2 * l3 + (l2 + 1) <= m - 3 * n) l2++; l1 = n - l4 - l3 - l2; //cout << l1 + l2 + l3 + l4 << " " << n << endl << 3 * l1 + 4 * l2 + 5 * l3 + 6 * l4 << " " << m << endl << m - 3 * n << " " << l2 + 2 * l3 + 3 * l4 << endl; } void out() { if(l1 < 0) printf("NIE"); else { while(l1--) putchar('a'); while(l2--) putchar('c'); while(l3--) putchar('g'); while(l4--) putchar('o'); } } int main() { in(); calc(); out(); } |