#include <iostream> int main() { int n; std::cin >> n; std::string m; std::cin >> m; int lefts = 0; for (int i = 0; i < n; ++i) { if (m[i] == 'L') ++lefts; } int rights = n - lefts; int opposites = 0; for (int i = 0; i < lefts; ++i) { if (m[i] == 'P') { std::cout << opposites * 2 + 1; ++opposites; } else { std::cout << opposites * 2; } std::cout << ' '; } for (int i = lefts; i < n; ++i) { if (m[i] == 'L') { --opposites; std::cout << opposites * 2 + 1; } else { std::cout << opposites * 2; } std::cout << ' '; } std::cout << std::endl; 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 | #include <iostream> int main() { int n; std::cin >> n; std::string m; std::cin >> m; int lefts = 0; for (int i = 0; i < n; ++i) { if (m[i] == 'L') ++lefts; } int rights = n - lefts; int opposites = 0; for (int i = 0; i < lefts; ++i) { if (m[i] == 'P') { std::cout << opposites * 2 + 1; ++opposites; } else { std::cout << opposites * 2; } std::cout << ' '; } for (int i = lefts; i < n; ++i) { if (m[i] == 'L') { --opposites; std::cout << opposites * 2 + 1; } else { std::cout << opposites * 2; } std::cout << ' '; } std::cout << std::endl; return 0; } |