#include <iostream>
using namespace std;
int main()
{
int n;
string s;
cin >> n;
cin >> s;
int count = 0; // count of 1's
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
count++;
}
}
if (count < 3 * n) {
cout << "NIE";
return 0;
}
if (count > 6 * n) {
cout << "NIE";
return 0;
}
int count_a = 0, count_c = 0, count_g = 0, count_o = 0;
while ((count - 3) >= 3) {
count -= 3;
count_a++;
}
while ((count - 4) >= 3) {
count -= 4;
count_c++;
}
while ((count - 5) >= 3) {
count -= 5;
count_g++;
}
if (count == 3) {
count_a++;
count -= 3;
}
if (count == 4) {
count_c++;
count -= 4;
}
if (count == 5) {
count_g++;
count -= 5;
}
if (count > 0) {
cout << "NIE";
return 0;
}
int x = count_a + count_c + count_g - n;
if (x > 0) {
count_a -= 2 * x;
count_o += x;
}
string ans = "";
for (int i = 0; i < count_a; i++) {
ans += 'a';
}
for (int i = 0; i < count_c; i++) {
ans += 'c';
}
for (int i = 0; i < count_g; i++) {
ans += 'g';
}
for (int i = 0; i < count_o; i++) {
ans += 'o';
}
cout << ans;
}
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 | #include <iostream> using namespace std; int main() { int n; string s; cin >> n; cin >> s; int count = 0; // count of 1's for (int i = 0; i < s.length(); i++) { if (s[i] == '1') { count++; } } if (count < 3 * n) { cout << "NIE"; return 0; } if (count > 6 * n) { cout << "NIE"; return 0; } int count_a = 0, count_c = 0, count_g = 0, count_o = 0; while ((count - 3) >= 3) { count -= 3; count_a++; } while ((count - 4) >= 3) { count -= 4; count_c++; } while ((count - 5) >= 3) { count -= 5; count_g++; } if (count == 3) { count_a++; count -= 3; } if (count == 4) { count_c++; count -= 4; } if (count == 5) { count_g++; count -= 5; } if (count > 0) { cout << "NIE"; return 0; } int x = count_a + count_c + count_g - n; if (x > 0) { count_a -= 2 * x; count_o += x; } string ans = ""; for (int i = 0; i < count_a; i++) { ans += 'a'; } for (int i = 0; i < count_c; i++) { ans += 'c'; } for (int i = 0; i < count_g; i++) { ans += 'g'; } for (int i = 0; i < count_o; i++) { ans += 'o'; } cout << ans; } |
English