1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "algorithm" 5 using namespace std; 6 char str[3010]; 7 int n; 8 9 int main() 10 { 11 int i, j, res = 0, pos; 12 char c; 13 scanf("%d%s", &n, str + 1); 14 str[n + 1] = ‘R‘; 15 for(i = 1; i <= n && str[i]==‘.‘; ++i); 16 if(str[i] == ‘R‘) { 17 res += (i - 1); 18 c = ‘R‘; 19 pos = i; 20 } else { 21 c = ‘L‘; 22 pos = i; 23 } 24 for(++i ; i <= n + 1; ++i) { 25 if(c == ‘R‘ && str[i] == ‘L‘) { 26 res += (i - pos - 1) & 1; 27 } 28 else if(c == ‘L‘ && str[i] == ‘R‘) { 29 res += (i - pos - 1); 30 } 31 if(str[i] != ‘.‘) { 32 c = str[i]; 33 pos = i; 34 } 35 } 36 printf("%d\n", res); 37 }
时间: 2024-12-25 10:12:22