SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
설명
주어진 N 길이의 숫자열을 오름차순으로 정렬한다.
풀이
정렬에 관한 내용 👇
[자료구조] sort, sorted, 정렬, 이중 리스트 정렬 (Python)
정렬 ✔ list.sort() - 오름차순으로 정렬 list = [3, 4, 2, 1, 5] list.sort() print(list) 출력 결과 [1, 2, 3, 4, 5] ✔ list.sort(reverse = True) - 내림차순으로 정렬 list = [3, 4, 2, 1, 5] list.sort(reverse=True) print(list) 출력 결
dev-cloud.tistory.com
Solution
t = int(input())
for i in range(1, t+1):
ans = 0
n = int(input())
num = list(map(int, input().split()))
ans = sorted(num)
print("#"+str(i),*ans)
num = []
※ ans앞에 *을 붙인 이유는 리스트에서 꺼내기 위함이다.
'SWEA' 카테고리의 다른 글
[SWEA] 1983. 조교의 성적 매기기 (Python/D2) (2) | 2023.11.02 |
---|---|
[SWEA] 1984. 중간 평균값 구하기 (Python/D2) (1) | 2023.11.01 |
[SWEA] 1936. 1대1 가위바위보 (Python) (0) | 2023.10.30 |
[SWEA] 2072. 홀수만 더하기 (Python) (0) | 2023.10.30 |
[SWEA] 1545. 거꾸로 출력해 보아요 (Python) (0) | 2023.10.30 |