Language: C++

void change(const int *p1, int *p2, const string &str)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (i == 0)//0特殊处理
		{
			if (str[1] == 'L')
			{
				p2[0] = p1[1];
			}
			else
			{
				p2[0] = 0;
			}
		}
		else if (i == (str.size() - 1))
		{
			if (str[str.size() - 2] == 'R')
			{
				p2[str.size() - 1] = p1[str.size() - 2];
			}
			else
			{
				p2[str.size() - 1] = 0;
			}
		}
		else
		{
			p2[i] = 0;
			if (str[i - 1] == 'R')
			{
				p2[i] += p1[i - 1];
			}
			if (str[i + 1] == 'L')
			{
				p2[i] += p1[i + 1];
			}
		}
	}
}


int main(void)
{
	int i;
	string S;
	char s;
	int con = 1;
	int max = 0;

	//Input the string
	cin >> S;

	int *pNumber1 = new int[S.size()];
	int *pNumber2 = new int[S.size()];
	//Output the string
	//for (i = 0; i < S.size(); i++)
	//{
	//	cout << S[i];
	//}
	//寻找最大的连续R和L

	s = S[0];
	pNumber1[0] = 1;
	for (i = 1; i < S.size(); i++)
	{
		pNumber1[i] = 1;
		if (s == S[i])
		{
			con++;
			if (con > max)
			{
				max = con;
			}
		}
		else
		{
			s = S[i];
			con = 1;
		}
	}

	//开始交换max次
	for (i = 0; i < max; i++)
	{
		if (i % 2 == 0)
		{
			change(pNumber1, pNumber2, S);
		}
		else
		{
			change(pNumber2, pNumber1, S);
		}
	}

	if (max % 2 != 0)
	{
		for (i = 0; i < S.size(); i++)
		{

			cout << pNumber1[i] << ' ';
		}
	}
	else
	{
		for (i = 0; i < S.size(); i++)
		{
			cout << pNumber2[i] << ' ';
		}
	}
//	cout << max;


	delete[] pNumber1;
	delete[] pNumber2;
	return 0;
}

Compiler output:
a.cc:1:43: error: 'string' does not name a type
    1 | void change(const int *p1, int *p2, const string &str)
      |                                           ^~~~~~
a.cc: In function 'void change(const int*, int*, const int&)':
a.cc:3:33: error: request for member 'size' in 'str', which is of non-class type 'const int'
    3 |         for (int i = 0; i < str.size(); i++)
      |                                 ^~~~
a.cc:7:32: error: invalid types 'const int[int]' for array subscript
    7 |                         if (str[1] == 'L')
      |                                ^
a.cc:16:36: error: request for member 'size' in 'str', which is of non-class type 'const int'
   16 |                 else if (i == (str.size() - 1))
      |                                    ^~~~
a.cc:18:37: error: request for member 'size' in 'str', which is of non-class type 'const int'
   18 |                         if (str[str.size() - 2] == 'R')
      |                                     ^~~~
a.cc:20:40: error: request for member 'size' in 'str', which is of non-class type 'const int'
   20 |                                 p2[str.size() - 1] = p1[str.size() - 2];
      |                                        ^~~~
a.cc:20:61: error: request for member 'size' in 'str', which is of non-class type 'const int'
   20 |                                 p2[str.size() - 1] = p1[str.size() - 2];
      |                                                             ^~~~
a.cc:24:40: error: request for member 'size' in 'str', which is of non-class type 'const int'
   24 |                                 p2[str.size() - 1] = 0;
      |                                        ^~~~
a.cc:30:32: error: invalid types 'const int[int]' for array subscript
   30 |                         if (str[i - 1] == 'R')
      |                                ^
a.cc:34:32: error: invalid types 'const int[int]' for array subscript
   34 |                         if (str[i + 1] == 'L')
      |                                ^
a.cc: In function 'int main()':
a.cc:46:9: error: 'string' was not declared in this scope
   46 |         string S;
      |         ^~~~~~
a.cc:52:9: error: 'cin' was not declared in this scope; did you mean 'con'?
   52 |         cin >> S;
      |         ^~~
      |         con
a.cc:52:16: error: 'S' was not declared in this scope
   52 |         cin >> S;
      |                ^
a.cc:101:25: error: 'cout' was not declared in this scope
  101 |                         cout << pNumber1[i] << ' ';
      |                         ^~~~
a.cc:108:25: error: 'cout' was not declared in this scope
  108 |                         cout << pNumber2[i] << ' ';
      |                         ^~~~