본문 바로가기
python-algorithm

백준 16466 콘서트

by 무적김두칠 2022. 10. 13.

https://www.acmicpc.net/problem/16466

 

16466번: 콘서트

HCPC (Hanyang Completely Perfect Celebrity)는 한양대학교 최고의 가수에게 주어지는 칭호이다. 한양대학교는 매년 최고의 HCPC를 선발한다. HCPC가 되기란 여간 어려운 게 아니다. 매일 아침 날달걀을 까먹

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
import sys
n=int(sys.stdin.readline())
nums=sorted(list(map(int, sys.stdin.readline().split())))
is_full=1
for i in range(len(nums)):
    if (i+1)!=nums[i]:
        print(i+1)
        is_full=0
        break
if is_full == 1:
    print(n+1)
cs

이 문제는 정렬 문제고, sort()함수써서 숫자 정렬시키고 index+1 번과 그 위치의 숫자가 일치하지 않으면 index+1 번을 출력하고
혹시 전부 일치하게 되면 n+1 을 출력하면됩니다!
This problem is about Sorting,
First you can sort numbers with sort() function
Second If Index+1 is not equal to (index+1)'s number print(index+1)
else print n+1

반응형

댓글