π λ¬Έμ νμνκΈ°
- νκΈ νλ‘κ·Έλ¨μ λ©λ΄μ μ΄ N(1 ≤ N ≤ 30)κ°μ μ΅μ
- κ° μ΅μ μ ν κ° λλ μ¬λ¬ κ°μ λ¨μ΄λ‘ μ΅μ κΈ°λ₯ μ€λͺ
- μμμλΆν° μ°¨λ‘λλ‘ κ° μ΅μ
μ λ¨μΆν€λ₯Ό μλ―Ένλ λν μνλ²³ μ§μ νκΈ°
- νλμ μ΅μ
μ λν΄ μΌμͺ½μμλΆν° μ€λ₯Έμͺ½ μμλ‘ λ¨μ΄μ 첫 κΈμκ° μ΄λ―Έ λ¨μΆν€λ‘ μ§μ λμλμ§ μ΄ν΄λ³΄κΈ°
- μμ§ μ§μ μ΄ μλμ΄μλ€λ©΄ κ·Έ μνλ²³μ΄ λ¨μΆν€
- λͺ¨λ λ¨μ΄μ 첫 κΈμκ° μ΄λ―Έ μ§μ λμ΄ μλ€λ©΄ μΌμͺ½μμλΆν° μ°¨λ‘λλ‘ μνλ²³μ 보면μ λ¨μΆν€λ‘ μ§μ μλ κ²μ λ¨μΆν€λ‘ μ§μ
- μ΄λ ν κ²λ λ¨μΆν€λ‘ μ§μ ν μ μλ€λ©΄ κ·Έλ₯ λλκΈ°
- λμλ¬Έμ ꡬλΆνμ§ μμ
- νλμ μ΅μ
μ λν΄ μΌμͺ½μμλΆν° μ€λ₯Έμͺ½ μμλ‘ λ¨μ΄μ 첫 κΈμκ° μ΄λ―Έ λ¨μΆν€λ‘ μ§μ λμλμ§ μ΄ν΄λ³΄κΈ°
- κ° μ΅μ μ μΆλ ₯νλ©° λ¨μΆν€λ‘ μ§μ λ μνλ²³μ μ’μ°μ [] κ΄νΈλ₯Ό μμμ νν
π μ½λ μ€κ³νκΈ°
- μ΅μ μ κ°μ N μ λ ₯ λ°κΈ°
- μ΅μ μ λνλ΄λ λ¬Έμμ΄ options 리μ€νΈλ‘ μ λ ₯ λ°κΈ°
- λ¨μΆμ΄ μνλ²³ μ¬μ© μ¬λΆλ₯Ό 체ν¬ν alphabets 리μ€νΈ Falseλ‘ μ΄κΈ°ν
- κ° μ΅μ μ λ¨μΆμ΄ μμΉλ₯Ό κΈ°λ‘ν shortcut_idx 리μ€νΈ 0μΌλ‘ μ΄κΈ°ν
- μ΅μ
νλλ§λ€ λ¨μΆμ΄ μ§μ κ·μΉμ λ°λΌ λ¨μΆμ΄λ₯Ό μ§μ νλ€.
- μ΅μ μ λ¨μ΄λ€ 첫κΈμλ₯Ό νμνλ©°, alphabetsμμ μμ§ μ¬μ©νμ§ μμλ€κ³ 체ν¬λ κΈμμ΄λ©΄ μ¬μ© μ²΄ν¬ νμ, λ¨μΆμ΄ μμΉλ₯Ό κΈ°λ‘νλ€.
- λͺ¨λ λ¨μ΄μ 첫κΈμλ₯Ό νμνλλ° μ¬μ ν shortcut_idx[cur]μ΄ -1μ΄λΌλ©΄, μμμλΆν° μ°¨λ‘λλ‘ λͺ¨λ κΈμλ₯Ό νμΈνλ©΄μ, alphabetsμμ μμ§ μ¬μ©νμ§ μμ κΈμκ° λμ¬λκΉμ§ νμνλ€.
- λͺ¨λ μ΅μ μ λν λ¨μΆμ΄ μ§μ μ΄ λλλ©΄, shortcut_idxμ λ°λΌ κ° μ΅μ λ¬Έμμ΄μ λ¨μΆμ΄μ [ ]λ₯Ό μΆκ°νμ¬ μΆλ ₯νλ€.
π μ λ΅ μ½λ
N = int(input())
options = [input().split() for _ in range(N)]
alphabets = [False]*26
shortcuts_idx = [0]*N
def check_shortcut(option_idx, word_idx, cur_alphabet):
cur_alphabet = ord(cur_alphabet.lower())
cur_alphabet = cur_alphabet - 97
if not alphabets[cur_alphabet]:
shortcuts_idx[option_idx] = word_idx
alphabets[cur_alphabet] = True
return True
return False
for n in range(N):
option = options[n]
isFound = False
# κ° λ¨μ΄ 첫κΈμ νμ
for i in range(len(option)):
if check_shortcut(n, (i, 0), option[i][0]):
isFound = True
break
# λ¨μ΄ 첫κΈμμμ λ¨μΆμ΄λ₯Ό μ§μ λͺ»νλ€λ©΄ λͺ¨λ κΈμ
if not isFound:
for i in range(len(option)):
for j in range(len(option[i])):
if check_shortcut(n, (i, j), option[i][j]):
isFound = True
break
if isFound:
break
for n in range(N):
option = options[n]
if not shortcuts_idx[n]:
print(*option)
else:
words = ""
for i in range(len(option)):
for j in range(len(option[i])):
if shortcuts_idx[n] == (i, j):
words += f'[{option[i][j]}]'
else:
words += option[i][j]
words += " "
print(words)
728x90