思路:青蛙跳的问题,青蛙只能跳‘R‘,不能跳‘L‘,问青蛙至少跳多少可以跳过,我们可以这么想这个问题,找到所有R之间的L,看看哪个L多,计算数量即可
代码:
#include<iostream> #include<string> #include<cmath> #include<algorithm> using namespace std; int main(){ int t, cnt, sum; char str[200005]; cin >> t; while (t--){ scanf("%s",str); sum=cnt = 0; int len = 0; len = strlen(str); for (int i = 0; i < len+1; i++){ if (str[i] == ‘L‘){ cnt++; } else{ sum = max(sum, cnt); cnt = 0; } } cout << sum+1 << endl; } return 0; }
原文:https://www.cnblogs.com/pcdl/p/12500964.html