#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(false); int n = 0, i = 0; cin >> n; int ones = 0, zeros = 0; n *= 8; while(i < n) { char c; cin >> c; if(c == '0') ++zeros, ++i; if(c == '1') ++ones, ++i; } string str = ""; while(zeros > 0 && ones > 0) { if(zeros > ones) { str.push_back('a'); zeros -= 5; ones -= 3; } else if(zeros == ones) { str.push_back('x'); zeros -= 4; ones -= 4; } else { if(ones-zeros >= 4) { str.push_back('w'); zeros -= 2; ones -= 6; } else { str.push_back('y'); zeros -= 3; ones -= 5; } } } if(zeros == 0 && ones == 0) { cout << str << endl; } else { cout << "NIE" << 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 40 41 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(false); int n = 0, i = 0; cin >> n; int ones = 0, zeros = 0; n *= 8; while(i < n) { char c; cin >> c; if(c == '0') ++zeros, ++i; if(c == '1') ++ones, ++i; } string str = ""; while(zeros > 0 && ones > 0) { if(zeros > ones) { str.push_back('a'); zeros -= 5; ones -= 3; } else if(zeros == ones) { str.push_back('x'); zeros -= 4; ones -= 4; } else { if(ones-zeros >= 4) { str.push_back('w'); zeros -= 2; ones -= 6; } else { str.push_back('y'); zeros -= 3; ones -= 5; } } } if(zeros == 0 && ones == 0) { cout << str << endl; } else { cout << "NIE" << endl; } } |