Codeforces Round #180 (Div. 2) A. Snow Footprints(简单)
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.
![](http://codeforces.ru/renderer/a5ac838d4abf7ca4b5a1d95f0e5617aa343d237a.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 the t-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.
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int main() 8 { 9 int n, s, t; 10 char str[1002]; 11 while(scanf("%d", &n) != EOF) 12 { 13 scanf("%s", str + 1); 14 int len = strlen(str + 1); 15 bool l = false, r = false; 16 for(int i = 1; i <= len; i++) 17 { 18 if(str[i] == 'L') l = true; 19 if(str[i] == 'R') r = true; 20 } 21 if(l && !r) 22 { 23 for(s = len; str[s] == '.'; s--){} 24 for(t = 1; str[t] == '.'; t++){} 25 t--; 26 printf("%d %d\n", s, t); 27 } 28 else if(!l && r) 29 { 30 for(t = len; str[t] == '.'; t--){} 31 t++; 32 for(s = 1; str[s] == '.'; s++){} 33 printf("%d %d\n", s, t); 34 } 35 else 36 { 37 for(s = len; str[s] == '.'; s--){} 38 for(t = s - 1; str[t] == str[s]; t--){} 39 t++; 40 if(str[s] == 'L') printf("%d %d\n", s, t); 41 else printf("%d %d\n", t, s); 42 } 43 } 44 return 0; 45 }