There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.
![](https://i-blog.csdnimg.cn/blog_migrate/8f3422b8bf227ba924cb49fa3a54ed78.png)
At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in thet-th block. It is known that Alice never moves outside of the road.
You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.
9 ..RRLL...
3 4
11 .RRRLLLLL..
7 5
The first test sample is the one in the picture.
#include<string.h>
const int MAX=1500;
char s[MAX];
using namespace std;
int main()
{
int n,m,i,j,start,end,q,p,a,b;
cin>>n;
cin>>s;
m=strlen(s);
a=0;
b=0;
p=1;
q=1;
for(i=1;i<m;i++)
{
if(s[i]=='.')
continue;
if((s[i]=='R'||s[i]=='L')&&p)//P的意思是为了得到开始点,因为执行一次后P为0,以后这个语句就不会执行了
{
p=0;
start=i+1;
}
if((s[i-1]=='R'&&s[i]=='L')||(s[i-1]=='L'&&s[i]=='R')&&q)//同理q和P一样
{
end=i;
q=0;
}
if(s[i]=='R')
a+=1;
if(s[i]=='L')
b+=1;
}
if(a!=0&&b!=0)//如果a和b都不为0那么上个for循环里的start和end就是结果了,如果不是下面要分情况讨论而且起始点和终点要重新得出
{
cout<<start<<" "<<end<<endl;
}
if(a==0&&b!=0)
{
for(i=0;i<n;i++)
{
if(s[i]!='.')
{
end=i;
break;
}
}
for(i=n-1;i>=0;i--)
{
if(s[i]!='.')
{
start=i+1;
break;
}
}
cout<<start<<" "<<end<<endl;
}
if(b==0&&a!=0)
{
for(i=0;i<n;i++)
{
if(s[i]!='.')
{
start=i+1;
break;
}
}
for(i=n-1;i>=0;i--)
{
if(s[i]!='.')
{
end=i+1;
break;
}
}
cout<<start<<" "<<end+1<<endl;
}
if(a==0&&b==0)//这个为全是'.'的情况,所以随便输出一个结果,当然结果要比n小
{
cout<<2<<" "<<2<<endl;
}
return 0;
} //如果有问题,或有什么疑惑,可以在评论中提出,小子我看到一定尽力解答
9 ..RRLL...
3 4
3 4
ok ok
11 .RRRLLLLL..
2 4
7 5
ok ok
17 .......RRRRR.....
8 13
12 13
ok ok
13 ....LLLLLL...
5 4
10 4
ok ok
Test: # 8, time: 0 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OKInput4 .RL.Output2 2Answer3 2Checker Logok okTest: # 9, time: 0 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OKInput3 .L.Output2 1Answer2 1Checker Logok okTest: # 10, time: 0 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OKInput3 .R.Output2 3Answer2 3Checker Logok ok