求某一整数序列的全排列问题
Time Limit:1000MS Memory Limit:65536K
Total Submit:45 Accepted:20
Description
现有一整数序列如:123,请计算出它的全排列。
Input
输入数据有两行组成,第一行为整数序列的长度,第二行为整数序列,序列元素之间以Tab符相隔。
Output
输出数据为整数序列的全排列,每一个排列单独占一行。
Sample Input
3
1 2 3
Sample Output
123
132
213
231
312
321
Source
/*
* http://183.167.205.82:8081/JudgeOnline/showproblem?problem_id=1048
* by jtahstu on 2015/2/7 7:00
* 知识点: 排列生成器 按字典序的下一个排列 next_permutation()
* 按字典序的前一个排列 prev_permutation()
*/
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
int m;
string s,a;
cin>>m;
for(int i=0; i<m; i++) {
cin>>a;
s+=a;
}
cout<<s<<endl;
while(next_permutation(s.begin(),s.end()))
cout<<s<<endl;
return 0;
}