#C13579. All Unique Permutations
All Unique Permutations
All Unique Permutations
Given an array of distinct integers, your task is to generate and print all unique permutations of the array.
For example, if the input array is [1, 2, 3]
, then the valid permutations are:
- 1 2 3
- 1 3 2
- 2 1 3
- 2 3 1
- 3 1 2
- 3 2 1
If the array is empty, print an empty line.
inputFormat
The input is provided via standard input (stdin). The first line contains an integer (n) ((0 \leq n \leq 10)), which denotes the number of elements in the array. If (n > 0), the second line contains (n) space-separated integers.
outputFormat
Print all unique permutations of the array, each permutation on a new line. Within each permutation, the numbers should be separated by a single space. If (n = 0), output a blank line. The order of permutations does not matter.## sample
3
1 2 3
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
</p>