-
[백준] 2750 수 정렬백준 Online Judge 2021. 8. 27. 15:26
문제 해설
- 처음 입력된 수는 숫자 개수이다.
- 2~n줄에는 숫자가 입력된다.
- 숫자를 작은 숫자부터 순서대로 출력한다.
선택 정렬로 해결하기
남은 원소 중에서 가장 작은 숫자를 앞으로 넣는다.
n = int(input()) num_list = list() for i in range(n): num_list.append(int(input())) for i in range(n): min_idx = i for j in range (i+1, n): if num_list[min_idx] > num_list[j]: min_idx = j num_list[i], num_list[min_idx] = num_list[min_idx], num_list[i] for i in range(n): print(num_list[i])
파이썬 기본 정렬 알고리즘으로 문제 풀이
n = int(input()) num_list = list() for i in range(n): num_list.append(int(input())) num_list.sort() for i in range(n): print(num_list[i])
GitHub - DAWUNHAN/Algorithms-and-DataStructure: Algorithms and DataStructure with Python
Algorithms and DataStructure with Python. Contribute to DAWUNHAN/Algorithms-and-DataStructure development by creating an account on GitHub.
github.com
[ 패스트캠퍼스 알고리즘 / 기술면접 완전 정복 올인원 패키지 Online ] 강의 내용을 정리한 자료입니다.
'백준 Online Judge' 카테고리의 다른 글
[백준] 10814 나이 순으로 정렬하기 (0) 2021.08.27 [백준] 1427 숫자 내림차순 정렬 (0) 2021.08.27 [백준] ⭐⭐ 4195 친구 네트워크 (0) 2021.08.26 [백준] 1920 수 찾기 (0) 2021.08.26 [백준] 10930 SHA-256 (0) 2021.08.26