题解:AT_joi2023_yo1a_c 3 つの箱 (Three Boxes)
因为 L 就减 R 就加
code:
#include<bits/stdc++.h>
using namespace std;
int n,m=1,ans;//m : 目前小球的位置 ans : 答案
string s;
int main(){
cin>>n>>s;
for(int i=0;i<n;i++){
if(s[i]=='L')x=max(x-1,1);//确保不超出范围
else x=min(3,x+1);
if(x==3)ans++;//更新答案
}cout<<ans;
return 0;
}