#include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, a = 0, b = 0; cin >> n; string res; for(int i = 0; i < 8 * n; ++i) { char c; cin >> c; if(c == '0') a++; else b++; } while(a > 0 & b > 0 && a != b) { if(a - b > 0) { a -= 5, b -= 3; res += 'a'; } else if(a - b > -4) { a -= 3, b -= 5; res += 'g'; } else { a -= 2, b -= 6; res += 'w'; } } while(a > 0) { res += 'c'; a -= 4, b -= 4; } if(a == 0 && b == 0) { cout << res << "\n"; } else { cout << "NIE\n"; } }
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 | #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, a = 0, b = 0; cin >> n; string res; for(int i = 0; i < 8 * n; ++i) { char c; cin >> c; if(c == '0') a++; else b++; } while(a > 0 & b > 0 && a != b) { if(a - b > 0) { a -= 5, b -= 3; res += 'a'; } else if(a - b > -4) { a -= 3, b -= 5; res += 'g'; } else { a -= 2, b -= 6; res += 'w'; } } while(a > 0) { res += 'c'; a -= 4, b -= 4; } if(a == 0 && b == 0) { cout << res << "\n"; } else { cout << "NIE\n"; } } |