#include <bits/stdc++.h> using namespace std; const int N = 8e5 + 7; const char ls[] = {'o', 'n', 'l', 'h'}; const int lcnt = sizeof(ls) / sizeof(ls[0]); char s[N]; int n, z; int solve(int a, int b) { for (int i = 0; i <= n; ++i) if (i * a + (n - i) * b == z) return i; return -1; } int main() { scanf("%d%s", &n, s); z = count(s, s + 8 * n, '0'); for (int i = 0; i < lcnt - 1; ++i) { int ans = solve(2 + i, 2 + i + 1); if (ans != -1) { for (int j = 0; j < ans; ++j) printf("%c", ls[i]); for (int j = 0; j < n - ans; ++j) printf("%c", ls[i + 1]); return 0; } } printf("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 | #include <bits/stdc++.h> using namespace std; const int N = 8e5 + 7; const char ls[] = {'o', 'n', 'l', 'h'}; const int lcnt = sizeof(ls) / sizeof(ls[0]); char s[N]; int n, z; int solve(int a, int b) { for (int i = 0; i <= n; ++i) if (i * a + (n - i) * b == z) return i; return -1; } int main() { scanf("%d%s", &n, s); z = count(s, s + 8 * n, '0'); for (int i = 0; i < lcnt - 1; ++i) { int ans = solve(2 + i, 2 + i + 1); if (ans != -1) { for (int j = 0; j < ans; ++j) printf("%c", ls[i]); for (int j = 0; j < n - ans; ++j) printf("%c", ls[i + 1]); return 0; } } printf("NIE"); return 0; } |