//Wojciech Filipek #include "bits/stdc++.h" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string bajty; cin >> bajty; int jeden = 0; int zero = 0; int a, b, c, d; a = 0; b = 0; c = 0; d = 0; for(int i = 0; i < bajty.length(); i++){ if(bajty[i] == '1') jeden++; else zero++; } //cout << "jeden: " << jeden << endl; //cout << "zero: " << zero << endl; if(jeden/n < 3 || zero/n < 2 || (zero+jeden)%8 != 0){ cout << "NIE" << endl; } else{ if(jeden > zero){ if(jeden/n == 6){ d = n; } else if(jeden/n == 5){ c = n; d = jeden - 5*n; c = n-d; } else if(jeden/n == 4){ b = n; c = jeden - 4*n; b = n-c; } else if(jeden/n == 3){ a = n; b = jeden - 3*n; a = n-b; } } else if(jeden < zero){ if(jeden/n == 6){ d = n; c = 6*n - jeden; d = n-c; } else if(jeden/n == 5){ c = n; b = 5*n - jeden; c = n-b; } else if(jeden == 3*n){ a = n; } else{ b = n; a = 4*n - jeden; b = n-a; } } else b = n; jeden = 0; zero = 0; for(int i = 0; i < a; i++){ cout << "a"; jeden += 3; zero += 5; } for(int i = 0; i < b; i++){ cout << "c"; jeden += 4; zero += 4; } for(int i = 0; i < c; i++){ cout << "g"; jeden += 5; zero += 3; } for(int i = 0; i < d; i++){ cout << "w"; jeden += 6; zero += 2; } //cout << endl; //cout << "Jeden: " << jeden << endl; //cout << "Zero: " << zero << 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | //Wojciech Filipek #include "bits/stdc++.h" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string bajty; cin >> bajty; int jeden = 0; int zero = 0; int a, b, c, d; a = 0; b = 0; c = 0; d = 0; for(int i = 0; i < bajty.length(); i++){ if(bajty[i] == '1') jeden++; else zero++; } //cout << "jeden: " << jeden << endl; //cout << "zero: " << zero << endl; if(jeden/n < 3 || zero/n < 2 || (zero+jeden)%8 != 0){ cout << "NIE" << endl; } else{ if(jeden > zero){ if(jeden/n == 6){ d = n; } else if(jeden/n == 5){ c = n; d = jeden - 5*n; c = n-d; } else if(jeden/n == 4){ b = n; c = jeden - 4*n; b = n-c; } else if(jeden/n == 3){ a = n; b = jeden - 3*n; a = n-b; } } else if(jeden < zero){ if(jeden/n == 6){ d = n; c = 6*n - jeden; d = n-c; } else if(jeden/n == 5){ c = n; b = 5*n - jeden; c = n-b; } else if(jeden == 3*n){ a = n; } else{ b = n; a = 4*n - jeden; b = n-a; } } else b = n; jeden = 0; zero = 0; for(int i = 0; i < a; i++){ cout << "a"; jeden += 3; zero += 5; } for(int i = 0; i < b; i++){ cout << "c"; jeden += 4; zero += 4; } for(int i = 0; i < c; i++){ cout << "g"; jeden += 5; zero += 3; } for(int i = 0; i < d; i++){ cout << "w"; jeden += 6; zero += 2; } //cout << endl; //cout << "Jeden: " << jeden << endl; //cout << "Zero: " << zero << endl; } } |