#include <iostream> char chrs[] = {'a', 'c', 'g', 'o'}; // 3 4 5 6 int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); unsigned n, nob; std::cin >> n; nob = n*8UL; unsigned jedynki = 0; for(unsigned i=0;i<nob;i++) { char c; std::cin >> c; if(c=='1') jedynki++; } unsigned cs = n*3UL; if(jedynki > cs*2UL) { std::cout << "NIE"; return 0; } if(jedynki < cs) std::cout << "NIE"; else if(jedynki == cs) { for(unsigned i=0;i<n;i++) putchar('a'); } else { unsigned r1 = jedynki-cs; unsigned c2 = r1/3; unsigned r2 = r1%3; char sub = 1; //printf("%u %u %u %u %u\n", jedynki, cs, r1, c2, r2); for(unsigned i=0;i<c2;i++) putchar('o'); if(r2) putchar(chrs[r2]); else sub = 0; for(unsigned i=c2;i<n-sub;i++) putchar('a'); } 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 | #include <iostream> char chrs[] = {'a', 'c', 'g', 'o'}; // 3 4 5 6 int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); unsigned n, nob; std::cin >> n; nob = n*8UL; unsigned jedynki = 0; for(unsigned i=0;i<nob;i++) { char c; std::cin >> c; if(c=='1') jedynki++; } unsigned cs = n*3UL; if(jedynki > cs*2UL) { std::cout << "NIE"; return 0; } if(jedynki < cs) std::cout << "NIE"; else if(jedynki == cs) { for(unsigned i=0;i<n;i++) putchar('a'); } else { unsigned r1 = jedynki-cs; unsigned c2 = r1/3; unsigned r2 = r1%3; char sub = 1; //printf("%u %u %u %u %u\n", jedynki, cs, r1, c2, r2); for(unsigned i=0;i<c2;i++) putchar('o'); if(r2) putchar(chrs[r2]); else sub = 0; for(unsigned i=c2;i<n-sub;i++) putchar('a'); } return 0; } |