[백준/파이썬] 16546번 풀이

업데이트:



문제 정보


풀이

문제

You are organizing a marathon with N runners. Every runner is given a distinct number from 1 to N, so they can be easily identified.

You record the number of each runner as they cross the finish line. Unfortunately, you notice that only N − 1 runners have finished. Which runner is still out there?

입력 요약
The first line of input contains the integer N (1 ≤ N ≤ 215). The next line contains N −1 distinct integers in the range from 1 to N, representing the numbers of runners who have crossed the finish line.

출력 요약
Output the number of the runner who has not crossed the finish line.

코드

print(*set([i+1 for i in range(int(input()))])-set(map(int,input().split())))

설명

핵심은 구현 관점에서 You are organizing a marathon with N runners. Every runner is given a distinct number from 1 to N, so they can be easily identified. …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기