题目链接------------------------------------
题解:只要青蛙一直往右跳,就能成功跳出,为了数据处理的方便,在左右边界分别加上R,该题就变成了寻找字符‘R’的位置差的最大值。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[200010];
int main(){
int t,n,i,mx,pre;//pre记录前一个R出现的位置
scanf("%d",&t);
while(t--){
scanf("%s",s+1);
n=strlen(s+1),mx=-1;
s[0]='R',n++,s[n]='R',pre=0;//边界处理
for(i=0;i<=n;i++)
if(s[i]=='R'){
mx=max(mx,i-pre);//R字符之间最大位置差值
pre=i;//刷新R的位置
}
printf("%d\n",mx);
}
return 0;
}