๋ฌธ์
https://www.acmicpc.net/problem/5052
ํ์ด
# ๋ฐฑ์ค 5052๋ฒ ๋ฌธ์ - ์ ํ๋ฒํธ ๋ชฉ๋ก
import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
phone_book = [str(sys.stdin.readline().strip()) for _ in range(n)] # ์ ํ๋ฒํธ๋ฅผ ๋ฌธ์์ด๋ก ๋ฐ๋๋ค.
phone_book.sort() # ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌํ์ฌ ์ฌ์ ์์ผ๋ก ์ ๋ ฌ
check = "YES" # ์ผ๊ด์ฑ์ด ์๋์ง ์ฒดํฌ
print(phone_book)
# ๋ฐ๋ณต๋ฌธ์ ํตํด ์ ํ๋ฒํธ๋ฅผ ํ์ธ
for i in range(len(phone_book) - 1):
# ํ์ฌ ์ ํ๋ฒํธ์ ๋ฌธ์์ด๊ณผ ๋ค์ ์ ํ๋ฒํธ์ ํ์ฌ ์ ํ๋ฒํธ ๊ธธ์ด๋งํผ์ ๋ฌธ์์ด๊ณผ ๊ฐ์์ง ํ์ธ
# ๊ฐ์ผ๋ฉด ์ผ๊ด์ฑ์ด ์๋ ๊ฒ
if phone_book[i] == phone_book[i + 1][0:len(phone_book[i])]:
check = "NO"
print(check)
ํ๋ก๊ทธ๋๋จธ์ค์ ์ ํ๋ฒํธ ๋ชฉ๋ก๊ณผ ๋น์ทํ ๋ฌธ์ ์ด๋ค.
https://school.programmers.co.kr/learn/courses/30/lessons/42577
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 1753๋ฒ_์ต๋จ๊ฒฝ๋ก (0) | 2023.04.16 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 9663๋ฒ_N-Queen (0) | 2023.04.15 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver4] 1302๋ฒ_๋ฒ ์คํธ์ ๋ฌ (0) | 2023.04.12 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 4179๋ฒ_๋ถ! (0) | 2023.04.11 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver5] 7785๋ฒ_ํ์ฌ์ ์๋ ์ฌ๋ (0) | 2023.04.11 |