#include <algorithm> #include <iostream> using namespace std; const int MAXN = 100000; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) char T[MAXN * 8 + 8]; char S[MAXN + 2]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; cin >> T; int zeros = 0, ones = 0; FOR(i, 8*n) { if(T[i] == '0') zeros++; else ones++; } // cout << zeros << "/" << ones << endl; int p = 0; while(zeros >= ones + 2 && ones >= 3) { S[p++] = 'a'; zeros -= 5; ones -= 3; } while(ones >= zeros + 4 && zeros >= 2) { S[p++] = 'w'; zeros -= 2; ones -= 6; } while(ones >= zeros + 2 && zeros >= 3) { S[p++] = 'z'; zeros -= 3; ones -= 5; } while(ones >= 4 && zeros >= 4) { S[p++] = 'l'; zeros -= 4; ones -= 4; } if(zeros == 0 && ones == 0) cout << S << 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 | #include <algorithm> #include <iostream> using namespace std; const int MAXN = 100000; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) char T[MAXN * 8 + 8]; char S[MAXN + 2]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; cin >> T; int zeros = 0, ones = 0; FOR(i, 8*n) { if(T[i] == '0') zeros++; else ones++; } // cout << zeros << "/" << ones << endl; int p = 0; while(zeros >= ones + 2 && ones >= 3) { S[p++] = 'a'; zeros -= 5; ones -= 3; } while(ones >= zeros + 4 && zeros >= 2) { S[p++] = 'w'; zeros -= 2; ones -= 6; } while(ones >= zeros + 2 && zeros >= 3) { S[p++] = 'z'; zeros -= 3; ones -= 5; } while(ones >= 4 && zeros >= 4) { S[p++] = 'l'; zeros -= 4; ones -= 4; } if(zeros == 0 && ones == 0) cout << S << endl; else cout << "NIE" << endl; } |