Problem Solving/BOJ
[BOJ][Python]5089번 정리
NoiB
2022. 6. 1. 20:21
반응형
https://www.acmicpc.net/problem/5089
5089번: Travelling Salesman
Output consists of a single line for each week. It contains the word Week, followed by a space, followed by the week number, the first week being 1, followed by a space, followed by the actual number of towns to be visited, duplicates having been removed.
www.acmicpc.net
cnt = 0
while 1:
cnt += 1
n = int(input())
if n == 0:
break
t = {input():1 for _ in range(n)}
print(f'Week {cnt} {len(t.keys())}')
딕셔너리 연습을 위해서 딕셔너리로 풀어봤습니다. 근데 집합을 써도 문제 없습니다. 저도 보자마자 바로 set으로 풀기도 했구요. set을 이용한 풀이도 올려봅니다.
cnt = 0
while 1:
cnt += 1
n = int(input())
if n == 0:
break
t = set([input() for _ in range(n)])
print(f'Week {cnt} {len(t)}')
반응형