#include <iostream> using namespace std; int main() { int n, c1 = 0; char c; cin>>n; for (int i = 0; i < 8 * n; ++i) { cin>>c; if (c == '1') ++c1; } if (c1 < 3 * n || c1 > 6 * n) { cout<<"NIE"<<endl; return 0; } else { while(n > 0) { if (c1 - 3 >= 3 * (n - 1) && c1 - 3 <= 6 * (n - 1)) { cout<<'a'; c1 -= 3; } else if (c1 - 4 >= 3 * (n - 1) && c1 - 4 <= 6 * (n - 1)) { cout<<'c'; c1 -= 4; } else if (c1 - 5 >= 3 * (n - 1) && c1 - 5 <= 6 * (n - 1)) { cout<<'g'; c1 -= 5; } else { cout<<'o'; c1 -= 6; } --n; } cout<<endl; } }
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 | #include <iostream> using namespace std; int main() { int n, c1 = 0; char c; cin>>n; for (int i = 0; i < 8 * n; ++i) { cin>>c; if (c == '1') ++c1; } if (c1 < 3 * n || c1 > 6 * n) { cout<<"NIE"<<endl; return 0; } else { while(n > 0) { if (c1 - 3 >= 3 * (n - 1) && c1 - 3 <= 6 * (n - 1)) { cout<<'a'; c1 -= 3; } else if (c1 - 4 >= 3 * (n - 1) && c1 - 4 <= 6 * (n - 1)) { cout<<'c'; c1 -= 4; } else if (c1 - 5 >= 3 * (n - 1) && c1 - 5 <= 6 * (n - 1)) { cout<<'g'; c1 -= 5; } else { cout<<'o'; c1 -= 6; } --n; } cout<<endl; } } |