代码:
#include<bits/stdc++.h>
using namespace std;
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main()
{
qwq;
int n, a[10] = {0}, res = 1;
cin >> n;
for (int i = 1; i <= n; i++)
{
a[i] = n - i + 1, res *= i;
}
for (int i = 1; i <= res - 1; i++)
{
next_permutation(a + 1, a + n + 1);
for (int j = 1; j <= n; j++)
{
printf("%5d", a[j]);
}
cout << endl;
}
return 0;
}