풀이
문제를 보았을때 알수있는 힌트
문제를 통해 순열을 출력하는 문제
- 1부터 N까지의 수를 출력
- 사전순으로 출력
이렇게 2가지를 조심하면서 문제를 풀어야할듯하다
문제를 풀기 위한 조건 정의
이 문제를 풀기 위해서 python에서는 itertools 라이브러리를 활용하면 쉽게 문제를 풀수있다.
itertools 라이브러리에 permutations 함수를 불러오면 순열을 불러오는 것은 끝이난다.
[1,2,3]을 가지고있는 순열을 뽑아보면
이런식으로 출력되는 것을 알 수 있다.
이를 이용해서 문제를 풀면
import sys
import itertools
def solution(mylist):
number= [x for x in range(1,mylist+1)]
answer= list(map(list, itertools.permutations(number)))
answer.sort()
return answer
n = int(input())
results = solution(n)
for i in results:
for j in i:
print(j,end=" ")
print("")
이렇게 코드를 짤수있다.
결과
전체 코드 공유
https://github.com/dydwkd486/coding_test/blob/main/baekjoon/baekjoon10974.py
'Coding Test > baekjoon' 카테고리의 다른 글
[백준 1316] 그룹 단어 체커 - python (solved.ac - 실버 5) (0) | 2022.01.04 |
---|---|
[백준 5052] 전화번호 목록 - python (solved.ac - 골드 4) (0) | 2021.12.17 |
[백준 7562] 나이트의 이동 - python (solved.ac - 실버 2) (0) | 2021.11.02 |
[백준 1037] 약수 - python (solved.ac - 실버 5) (0) | 2021.09.11 |
[백준 2231] 분해합 - python (solved.ac - 브론즈 2) (0) | 2021.07.29 |