fork download
  1. n=int(input())
  2. l=[]
  3. u=[]
  4. a=[]
  5. while n:
  6. l.append(n%10)
  7. n//=10
  8. u.append(0)
  9. a.append(0)
  10. n=len(l)
  11. def backtracking(k):
  12. if k==n:
  13. for i in a:
  14. print(i,end="")
  15. print()
  16. else:
  17. for i in range(n):
  18. if u[i]==0:
  19. a[k]=l[i]
  20. u[i]=1
  21. backtracking(k+1)
  22. a[k]=0
  23. u[i]=0
  24. backtracking(0)
Success #stdin #stdout 0.06s 14124KB
stdin
123
stdout
321
312
231
213
132
123