全排列
(蓝桥杯考场忘了函数如何拼写,对自己无语…)
bool next_permutation(iterator start, iterator end) // 字典序从小到大
bool prev_permutation(iterator start, iterator end) // 字典序从大到小
头文件: #include <algorithm>
函数功能: 把序列当前的排列 [ s t a r t , e n d ) [start,end) [start,end)更改为按字典序的下一排列,并返回 t r u e true true。若当前排列已经是序列所有排列中字典序最大的,返回 f a l s e false false。常用于输出一个序列按字典序从小到大的所有排列。
代码: vjudge 全排列题目
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// 全排列
int main(){
string str;
cin >> str;
// 先要对字符串从小到大排序
sort(str.begin(), str.end());
do{
cout << str <<"\n";
}while(next_permutation(str.begin(), str.end()));
return 0;
}