C++STL-全排列

C++STL-全排列

“ABCDE”
AB,AC, AD,AE,BC,BD,BE,CD,CE,DE
诸如此类

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
    string s = "ABCDE";
    string s1 = s.substr(0, 2);
    while(next_permutation(s.begin(), s.end())){
        if (s1 != s.substr(0,2) && s1[0] < s1[1])
            cout << s1 << endl;
        s1 = s.substr(0, 2);
    }
    return 0;
}

这里写图片描述

你可能感兴趣的:(C++STL-全排列)