1 solutions
-
0
C++ :
#include <bits/stdc++.h> #define N 100005 using namespace std; string s; int L[N],R[N]; int main(){ int n; cin >> n; cin >> s; int last = N; //先统计往右倒 for (int i = 0;i<n;i++){ if (s[i] == 'R') last = 0; else if (s[i] == 'L') last = N; else if (last!=N) last ++; R[i] = last; } //再统计往左倒 last = N; for (int i = n-1;i>=0;i--){ if (s[i] == 'L') last = 0; else if (s[i] == 'R') last = N; else if (last!=N) last ++; L[i] = last; } for (int i = 0;i<n;i++){ if (L[i]<R[i]) cout << "L"; else if (L[i]>R[i]) cout << "R"; else cout << "."; } return 0; }
- 1
Information
- ID
- 200
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By