728x90
반응형
https://www.acmicpc.net/problem/10974
10974번: 모든 순열
N이 주어졌을 때, 1부터 N까지의 수로 이루어진 순열을 사전순으로 출력하는 프로그램을 작성하시오.
www.acmicpc.net
<전체 코드>
def func(arr, ans=''):
l = len(arr)
if l == 1:
ans += str(arr.pop())
print(ans)
else:
for i in range(l):
temparr = arr[:]
tempans = ans+str(temparr.pop(i))+' '
func(temparr, tempans)
n = int(input())
arr = [i for i in range(1, n+1)]
func(arr)
728x90
반응형
'# Coding > # 백준' 카테고리의 다른 글
[백준 / 1034] 램프 - Python (0) | 2021.12.10 |
---|---|
[백준 / 1013] Contact - Python (0) | 2021.12.02 |
[백준 / 13305] 주유소 - Python (0) | 2021.07.23 |
[백준 / 11779] 최소비용 구하기 2 - Python (0) | 2021.07.23 |
[백준 / 14503] 로봇 청소기 - Python (0) | 2021.07.23 |