做题过程中经常有全排列问题,直接用 STL 中的 next_permutation 方法其实就可以了(需要 #include < algorithm >)。
#include <iostream>
#include <string>
#include <algorithm> // for "next_permutation"
using namespace std;
void Permutation(string str) {
if (str.length() == 0) return;
// sort(str.begin(), str.end()); 想要全排列就先 sort 即可
while (next_permutation(str.begin(), str.end())