#C13042. Lexicographic Permutations
Lexicographic Permutations
Lexicographic Permutations
Given a positive integer \(n\), your task is to generate all unique permutations of the digits from 1 to \(n\) and print them in lexicographical order.
The output should list each permutation on a new line. For example:
- For \(n = 1\): the output is
1
. - For \(n = 2\): the output is
12
followed by21
on the next line. - For \(n = 3\): the output is
123
,132
,213
,231
,312
, and321
, each on its own line.
Remember to follow stdin
for input and stdout
for output.
inputFormat
The input consists of a single integer \(n\) (\(1 \le n \le 9\)) provided via standard input.
outputFormat
Output all the lexicographically ordered permutations of the digits from 1 to \(n\). Each permutation should be printed in a new line.
## sample1
1
</p>