#include <bits/stdc++.h> using namespace std; const char *table = "...acgw"; void solve(int n, string s) { int count_ones = count(s.begin(), s.end(), '1'); if (!(3 * n <= count_ones && count_ones <= 6 * n)) { cout << "NIE\n"; return; } int k = count_ones / n; int count_upper = count_ones - n * k; int count_lower = n - count_upper; for (int i = 0; i < count_lower; i++) { cout << table[k]; } for (int i = 0; i < count_upper; i++) { cout << table[k+1]; } cout << endl; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; solve(n, s); }
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 | #include <bits/stdc++.h> using namespace std; const char *table = "...acgw"; void solve(int n, string s) { int count_ones = count(s.begin(), s.end(), '1'); if (!(3 * n <= count_ones && count_ones <= 6 * n)) { cout << "NIE\n"; return; } int k = count_ones / n; int count_upper = count_ones - n * k; int count_lower = n - count_upper; for (int i = 0; i < count_lower; i++) { cout << table[k]; } for (int i = 0; i < count_upper; i++) { cout << table[k+1]; } cout << endl; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; solve(n, s); } |