#include <iostream>
#include<algorithm>
using namespace std;
int a[10];
int main(int argc, char *argv[])
{
int i;
int N;
while(cin>>N)
for(i=0;i<N;i++) a[i]=i+1;
do
{
for(i=0;i<N;i++)
cout<<a[i]<<" ";
cout<<endl;
}
while(next_permutation(a,a+N));
return 0;
}
原文:http://www.cnblogs.com/2014acm/p/3891748.html