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
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<string>
using namespace std;

int main()
{
  unsigned int n, cnt_L = 0;
  string s;
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);  
  cin >> n;
  unsigned int *refl = new unsigned int[n]; // Liczba odbić
  cin >> s;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == 'L')
      cnt_L++;
    refl[i] = 0;  
  }
  unsigned int j_begin = 1; // Od którego miejsca szukać 'L'
  for (unsigned int i = 0; i < cnt_L; i++)
  {    
    if (s[i] == 'L')
    {
      if (j_begin <= i)
        j_begin = i + 1;
    }
    else
    {
      // Na pewno jest 'L' w s[j_begin..], bo i < cnt_L.
      unsigned int j = j_begin; 
      while (s[j] != 'L') 
        j++;
      unsigned int next_L = j;
      // cout << j_begin << ".." << next_L << "\n";
      j_begin = next_L + 1;
      s[i] = 'L';
      s[next_L] = 'P';
      // cout << s << "\n";   
      // Teraz ciąg zaczyna się od i znaków 'L'.
      refl[i]++;
      for (j = i + 1; j < next_L; j++)
        refl[j] += 2;
      refl[next_L]++;
    }
  }
  cout << refl[0];
  for (unsigned int i = 1; i < n; i++)
    cout << " " << refl[i];
  cout << "\n";
  delete[] refl;
  // system("pause");
}