C. Frog Jumps

C. Frog Jumps

题意

一行字符串由L和R组成,数组从1标号到n。青蛙从0的位置开始起跳,想到达n+1的位置,当他跳到L的时候只能往左跳,跳到R的时候只能往右跳,跳的范围由你来定。问最小的d是多少

思路

d = 连续最长的L+1。

代码实现

#include<bits/stdc++.h>
using namespace std;
int main(void){
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        int len = s.size();
        int cnt = 0;
        int maxx = 0;
        int cnt1 = 0;
        for(int i = 0; i < len; i++){
            if(s[i]=='R'){
                cnt++;
                cnt1 = 0;
            }
            else{
                cnt1++;
                if(cnt1 > maxx) maxx = cnt1;
            }
        }
        if(cnt==len) cout<<"1"<<endl;
        else{
            cout<<maxx+1<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/AC-AC/p/12503134.html