#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
int arry[n+1];
for(int i=1;i<=n;i++)arry[i]=i;
do
{
for(int i=1;i<=n;i++)cout<<" "<<arry[i];
cout<<endl;
}
while(next_permutation(arry+1,arry+1+n));
return 0;
}
思路分析:一个stl就行了(但注意prev_permutation是内部降序,next_permutation是内部升序就好了)