Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 645 Bytes

풀이_10974.md

File metadata and controls

23 lines (18 loc) · 645 Bytes

🐯 백준 10974 - 모든 순열

  • Date : 2021.06.06(일)
  • Time : 10분

문제

  • N이 주어졌을 때, 1부터 N까지의 수로 이루어진 순열을 사전순으로 출력하는 프로그램을 작성하시오.

코드 풀이

from itertools import permutations

N = int(sys.stdin.readline())
arr = [i for i in range(1, N+1)]

for numbers in list(permutations(arr)):
    for num in numbers:
        print(num, end=' ')
    print()

: permutations는 순열을 구하는 파이썬 내장 함수이다. 먼저 1~n까지의 숫자가 들어가 있는 배열을 만들어 준 뒤 순열을 구하면된다.