Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 242 Solved: 112
Description
給定n個數 a[0] , a[1] ........ a[n-1], 輸出其全排列。
Input
第一行輸入一個數n,(n<7)
接下來一行輸入n個數。
Output
按字典序從小到大輸出全排列
Sample Input
3 1 2 3 3 1 2 2
Sample Output
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 1 2 2 2 1 2 2 2 1
HINT
Source
題解:記錄一下全排列的格式
代碼:
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[10];
int main()
{
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
do
{
cout<<a[0];
for(int i=1;i<n;i++)
cout<<" "<<a[i];
cout<<endl;
}while(next_permutation(a,a+n));
}
return 0;
}