标签:
#include <iostream> #include <algorithm> #include<stdio.h> #include<string.h> #include<stdlib.h> using namespace std; int n,m; void per(char* list, int length) { sort(list, list + length); do { for(int i = 0; i < length; i++) { if(i == length-1) { cout << list[i]; } else { cout << list[i] << " "; } } cout << endl; }while(next_permutation(list, list + length)); } int main() { char a[2100]; while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<n;i++) { a[i] = (i+1)+'0'; } a[n] = '\0'; per(a,(int)strlen(a)); } return 0; }
<pre name="code" class="cpp"> #include <iostream> #include <algorithm> #include <iterator> #include<stdio.h> #include<string.h> using namespace std; int a[1001]; int n,m; int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<n;i++) { a[i] = i+1; } do { for(int i=0;i<n;i++) { if(i == n-1) { printf("%d\n",a[i]); } else { printf("%d ",a[i]); } } } while( next_permutation(a,a+n)); } return 0; }
标签:
原文地址:http://blog.csdn.net/yeguxin/article/details/45842807