Link : judge.koreatech.ac.kr/problem.php?id=1172
Python
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
from sys import stdin
testcase = int(stdin.readline().strip())
while testcase:
save = []
arr = list(map(str, stdin.readline().strip()))
before = '.'
# 변환 점을 기억함
for i, val in enumerate(arr):
if before != val:
if val != '.':
save.append([val, i])
before = val
before = '.'
pos = 0
while len(save):
stack = save.pop(0)
if len(save) == 0:
if stack[0] == 'R':
for i in range(stack[1], len(arr)):
arr[i] = 'R'
elif stack[0] == 'L':
for i in range(pos + 1, stack[1]):
arr[i] = 'L'
pos = stack[1]
break
else:
if stack[0] == 'R' and save[0][0] == 'L':
point = (save[0][1] - stack[1] - 1) // 2
pos = save[0][1]
for i in range(stack[1] + 1, stack[1] + point + 1):
arr[i] = 'R'
for i in range(save[0][1] - point, save[0][1]):
arr[i] = 'L'
save.pop(0)
else:
if stack[0] == 'L':
for i in range(pos, stack[1]):
arr[i] = 'L'
pos = stack[1]
elif stack[0] == 'R':
for i in range(stack[1] + 1, save[0][1]):
arr[i] = 'R'
print(''.join(arr))
testcase -= 1
|
cs |
FeedBack
cjw.git@gmail.com
'알고리즘 > 소스코드' 카테고리의 다른 글
PROGRAMMERS 42883: 큰 수 만들기 (0) | 2020.12.18 |
---|---|
PROGRAMMERS 42576: 완주하지 못한 선수 (0) | 2020.12.18 |
KOREATECH 1125: 좌우로 밀착 I (0) | 2020.12.16 |
KOREATECH 1119: 제스쳐 컨트롤 II (0) | 2020.12.16 |
KOREATECH 1116: 짝궁 문자열 (0) | 2020.12.15 |
댓글