#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; int* result = new int[n]; for(int i = 0; i < n; i++) result[i] = 0; string s; cin >> s; bool odbiciaWykryte = false; int i = 0; do { odbiciaWykryte = false; for(i = 0; i < n-1; i++) if(s[i] == 'P' && s[i+1] == 'L') { s[i] = 'L'; s[i+1] = 'P'; result[i]++; result[i+1]++; odbiciaWykryte = true; } } while(odbiciaWykryte == true); for(int i = 0; i < n; i++) cout << result[i] << " "; cout << endl; delete [] result; 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 43 | #include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; int* result = new int[n]; for(int i = 0; i < n; i++) result[i] = 0; string s; cin >> s; bool odbiciaWykryte = false; int i = 0; do { odbiciaWykryte = false; for(i = 0; i < n-1; i++) if(s[i] == 'P' && s[i+1] == 'L') { s[i] = 'L'; s[i+1] = 'P'; result[i]++; result[i+1]++; odbiciaWykryte = true; } } while(odbiciaWykryte == true); for(int i = 0; i < n; i++) cout << result[i] << " "; cout << endl; delete [] result; return 0; } |