#include <cstdio> #include <cstring> int n, l, p, ile, w[300005]; char s[300005]; int main() { scanf("%d %s", &n, s)?:0; for (int i=0; i<n; i++) { if (s[i] == 'L') l++; else p++; } for (int i=0; i<l; i++) { if (ile % 2 == 0) w[i] = ile; else w[i] = ++ile; if (s[i] == 'P') w[i] = ++ile; } ile = 0; for (int i=n-1; i>=l; i--) { if (ile % 2 == 0) w[i] = ile; else w[i] = ++ile; if (s[i] == 'L') w[i] = ++ile; } for (int i=0; i<n; i++) printf("%d ", w[i]); puts(""); }
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 | #include <cstdio> #include <cstring> int n, l, p, ile, w[300005]; char s[300005]; int main() { scanf("%d %s", &n, s)?:0; for (int i=0; i<n; i++) { if (s[i] == 'L') l++; else p++; } for (int i=0; i<l; i++) { if (ile % 2 == 0) w[i] = ile; else w[i] = ++ile; if (s[i] == 'P') w[i] = ++ile; } ile = 0; for (int i=n-1; i>=l; i--) { if (ile % 2 == 0) w[i] = ile; else w[i] = ++ile; if (s[i] == 'L') w[i] = ++ile; } for (int i=0; i<n; i++) printf("%d ", w[i]); puts(""); } |