码迷,mamicode.com
首页 > 其他好文 > 详细

C - Frog Jumps

时间:2020-03-14 23:29:12      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:das   imu   output   ssis   for   namespace   www   while   font   

There is a frog staying to the left of the string s=s1s2sns=s1s2…sn consisting of nn characters (to be more precise, the frog initially stays at the cell 00). Each character of ss is either ‘L‘ or ‘R‘. It means that if the frog is staying at the ii-th cell and the ii-th character is ‘L‘, the frog can jump only to the left. If the frog is staying at the ii-th cell and the ii-th character is ‘R‘, the frog can jump only to the right. The frog can jump only to the right from the cell 00.

Note that the frog can jump into the same cell twice and can perform as many jumps as it needs.

The frog wants to reach the n+1n+1-th cell. The frog chooses some positive integer value dbefore the first jump (and cannot change it later) and jumps by no more than dd cells at once. I.e. if the ii-th character is ‘L‘ then the frog can jump to any cell in a range [max(0,id);i1][max(0,i−d);i−1], and if the ii-th character is ‘R‘ then the frog can jump to any cell in a range [i+1;min(n+1;i+d)][i+1;min(n+1;i+d)].

The frog doesn‘t want to jump far, so your task is to find the minimum possible value of dd such that the frog can reach the cell n+1n+1 from the cell 00 if it can jump by no more than dd cells at once. It is guaranteed that it is always possible to reach n+1n+1 from 00.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1t1041≤t≤104) — the number of test cases.

The next tt lines describe test cases. The ii-th test case is described as a string ss consisting of at least 11and at most 21052⋅105 characters ‘L‘ and ‘R‘.

It is guaranteed that the sum of lengths of strings over all test cases does not exceed 21052⋅105 (|s|2105∑|s|≤2⋅105).

Output

For each test case, print the answer — the minimum possible value of dd such that the frog can reach the cell n+1n+1 from the cell 00 if it jumps by no more than dd at once.

Example

Input
6
LRLRRLL
L
LLR
RRRR
LLLLLL
R
Output
3
2
3
1
7
1

不需要想太多,找出来最远的两个r即可,注意一下首尾都是r

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;



int main()
{
    int t;
    scanf("%d", &t);
    while (t--) {
        string s;
        cin >> s;
        int len = s.length();
        s[len] = R;
        int ans = 1;
        for (int i = len - 1; i >= 0; i--) {
            if (s[i] == R) {
                ans = max(ans, len - i);
                len = i;
            }
        }
        if (s[0] != R) {
            ans = max(ans, len + 1);
        }
        cout << ans << endl;
    }




    return 0;
}

 

C - Frog Jumps

标签:das   imu   output   ssis   for   namespace   www   while   font   

原文地址:https://www.cnblogs.com/Vetsama/p/12495017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!