代码:
#include <iostream>
using namespace std;
int n;
int a[10];
bool r[10];
void print(int k)
{for(int i=1; i<=k; i++){cout<<a[i]<<" ";}cout<<endl;
}
void fun(int k)
{for(int i=1; i<=n; i++){if(r[i] == false){a[k] = i;r[i] = true;if(k == n){print(k);}else{fun(k+1);}r[i] = false;}}
}
int main()
{cin>>n;fun(1);return 0;
}