close
Content

顧名思義,這題就是要你生出1N所有的排列。

Input

輸入只有一個正整數N。(1N10)

 

Output

請輸出1N的所有排列,每個排列都以一行N個數字輸出,並請按照字典序輸出。

兩個陣列a[1],a[2],,a[N]b[1],b[2],,b[N] 如果滿足存在1kN使得a[1]=b[1],a[2]=b[2],,a[k1]=b[k1]a[k]<b[k],則a這個陣列的字典序比b小。

Sample Input #1
3
Sample Output #1
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

python:

from itertools import permutations
from sys import stdin
n=int(stdin.readline())
arr=[str(ifor i in range(1,n+1)]
p=permutations(arr)
for j in p:
    print(' '.join(j))
arrow
arrow
    創作者介紹
    創作者 趴趴熊日常 的頭像
    趴趴熊日常

    資工趴趴熊的小天地

    趴趴熊日常 發表在 痞客邦 留言(0) 人氣()