#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; int m; int s1, s2, s3, s4; string s; cin >> n; int j = 0, z = 0; cin >> s; for(int i = 0; i < s.size(); i++) { if (s[i] == '1') { j++; } else { z++; } } // cout << s.length() << " " << j + z << endl; // cout << j << " " << z << endl; j -= 2*n; z -= n; if (j >= 0 && z >= 0) { j -= n; z -= 4 * n; if (j >= 0 && z <= 0) { m = j; if (m <= 3 * n) { if (j+z == 0) { s4 = m/3; if (m % 3 == 1) { s2 = 1; s3 = 0; } else if (m % 3 == 2) { s2 = 0; s3 = 1; } else { s2 = 0; s3 = 0; } s1 = n-s4-s3-s2; for (int i = 0; i < s1; i++) { cout << 'a'; } for (int i = 0; i < s2; i++) { cout << 'c'; } for (int i = 0; i < s3; i++) { cout << 'g'; } for (int i = 0; i < s4; i++) { cout << 'o'; } return 0; } } } } cout << "NIE"; return 0; }
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 | #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; int m; int s1, s2, s3, s4; string s; cin >> n; int j = 0, z = 0; cin >> s; for(int i = 0; i < s.size(); i++) { if (s[i] == '1') { j++; } else { z++; } } // cout << s.length() << " " << j + z << endl; // cout << j << " " << z << endl; j -= 2*n; z -= n; if (j >= 0 && z >= 0) { j -= n; z -= 4 * n; if (j >= 0 && z <= 0) { m = j; if (m <= 3 * n) { if (j+z == 0) { s4 = m/3; if (m % 3 == 1) { s2 = 1; s3 = 0; } else if (m % 3 == 2) { s2 = 0; s3 = 1; } else { s2 = 0; s3 = 0; } s1 = n-s4-s3-s2; for (int i = 0; i < s1; i++) { cout << 'a'; } for (int i = 0; i < s2; i++) { cout << 'c'; } for (int i = 0; i < s3; i++) { cout << 'g'; } for (int i = 0; i < s4; i++) { cout << 'o'; } return 0; } } } } cout << "NIE"; return 0; } |