🚩 코딩테스트/알고리즘
[백준] 5052번: 전화번호 목록
딩딩크롱
2023. 5. 29. 23:57
728x90
문제
https://www.acmicpc.net/problem/5052
5052번: 전화번호 목록
첫째 줄에 테스트 케이스의 개수 t가 주어진다. (1 ≤ t ≤ 50) 각 테스트 케이스의 첫째 줄에는 전화번호의 수 n이 주어진다. (1 ≤ n ≤ 10000) 다음 n개의 줄에는 목록에 포함되어 있는 전화번호가
www.acmicpc.net
풀이
전화번호 목록을 정렬합니다.
그러면 전화번호 목록의 앞뒤의 시작이 같은지만 확인하면 됩니다.
코드
파이썬
import sys
input = sys.stdin.readline
def solution():
for i in range(n-1):
if phone_num[i+1].startswith(phone_num[i]):
return "NO"
return "YES"
t = int(input())
for _ in range(t):
n = int(input())
phone_num = sorted([input().rstrip() for _ in range(n)])
print(solution())
728x90