위에서 start배열 swap
아래서부터 받아온 last 배열 swap
후 비교해주며 *, - 더해주기
import sys
input = sys.stdin.readline
k, n = int(input()), int(input())
start = []
for i in range(k):
start.append(chr(ord('A') + i))
last = list(input().rstrip())
ladder_game = [list(input().rstrip()) for _ in range(n)]
flag = 0
for row in range(n):
if flag: break
for col in range(k - 1):
if ladder_game[row][col] == '-':
start[col], start[col + 1] = start[col + 1], start[col]
elif ladder_game[row][col] == '?':
flag = 1
break
flag = 0
for row in range(n - 1, -1, -1):
if flag: break
for col in range(k - 1):
if ladder_game[row][col] == '-':
last[col], last[col + 1] = last[col + 1], last[col]
elif ladder_game[row][col] == '?':
flag = 1
break
answer = ''
for i in range(k - 1):
if start[i] == last[i + 1] and start[i + 1] == last[i] and (i==0 or answer[-1] == '*'):
start[i], start[i + 1] = start[i + 1], start[i]
answer += '-'
elif start[i] == last[i]:
answer += '*'
if len(answer) != k - 1:
answer = 'x' * (k-1)
print(answer)
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 2776 암기왕 (0) | 2021.10.21 |
---|---|
[백준][Python] 20168 골목대장 호석 (0) | 2021.10.20 |
[백준][Python] 2729 이진수 덧셈 (0) | 2021.10.19 |
[백준][Python] 1987 알파뱃 (0) | 2021.10.19 |
[백준][Python] 18115 카드 놓기 (0) | 2021.10.19 |