#include<cstdio> using namespace std; int main() { int n; char nr; int ones = 0, zeros = 0; scanf("%d", &n); for(int i = 0; i < 8*n; i++) { scanf(" %c", &nr); if(nr=='0') zeros++; else ones++; } ones-= n*3; zeros-=n*2; if(ones < 0 || zeros < 0) printf("NIE"); else { while(ones >= 3 && n >= 1) { ones -= 3; n -= 1; printf("o"); } if (ones == 2 && n >= 1) { ones -= 2; n -= 1; printf("y"); } if (ones == 1 && n >= 1) { ones -= 1; n -= 1; printf("x"); } for(int i = n; i > 0; i--) printf("a"); } }
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<cstdio> using namespace std; int main() { int n; char nr; int ones = 0, zeros = 0; scanf("%d", &n); for(int i = 0; i < 8*n; i++) { scanf(" %c", &nr); if(nr=='0') zeros++; else ones++; } ones-= n*3; zeros-=n*2; if(ones < 0 || zeros < 0) printf("NIE"); else { while(ones >= 3 && n >= 1) { ones -= 3; n -= 1; printf("o"); } if (ones == 2 && n >= 1) { ones -= 2; n -= 1; printf("y"); } if (ones == 1 && n >= 1) { ones -= 1; n -= 1; printf("x"); } for(int i = n; i > 0; i--) printf("a"); } } |