#include <iostream>
#include <vector>
int main() {
int n;
std::cin >> n;
std::string ants;
std::cin.ignore();
std::getline(std::cin, ants);
std::vector<int> count(n, 0);
bool f = true;
while(f) {
f = false;
for(int i = 0; i < n - 1; ++i) {
if(ants[i] == 'P' && ants[i + 1] == 'L') {
ants[i] = 'L';
ants[i + 1] = 'P';
++count[i];
++count[i + 1];
++i;
f = true;
}
}
}
for(int i : count) {
std::cout << i << ' ';
}
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 <iostream> #include <vector> int main() { int n; std::cin >> n; std::string ants; std::cin.ignore(); std::getline(std::cin, ants); std::vector<int> count(n, 0); bool f = true; while(f) { f = false; for(int i = 0; i < n - 1; ++i) { if(ants[i] == 'P' && ants[i + 1] == 'L') { ants[i] = 'L'; ants[i + 1] = 'P'; ++count[i]; ++count[i + 1]; ++i; f = true; } } } for(int i : count) { std::cout << i << ' '; } return 0; } |
English