// next_permutation example #include <iostream> // std::cout #include <algorithm> // std::next_permutation, std::sort int make_combination(int myints[], int start , int end, int requirement_number){ //std::cout<<"start:"<<start<<"end:"<<end<<"requirement_number:"<<requirement_number<<std::endl; if (start == end){ std::cout << myints[start] << ","; requirement_number--; if (requirement_number >= 1){ std::cout << "not ok" << std::endl; return 1; }else { std::cout << std::endl; return 0; } } if (1 ==requirement_number){ requirement_number--; std::cout << myints[start] << std::endl; return 0; } std::cout<<myints[start]; requirement_number--; return make_combination(myints, start+1, end, requirement_number ); } int main () { int myints[] = {1,2,3}; std::sort (myints,myints+3); int i =0; for(; i<3; i++){ make_combination(myints, i, 2, 1); } // std::cout << "The 3! possible permutations with 3 elements:\n"; // do { // std::cout << myints[0] << ‘ ‘ << myints[1] << ‘ ‘ << myints[2] << ‘\n‘; // } while ( std::prev_permutation(myints,myints+3) ); // // std::cout << "After loop: " << myints[0] << ‘ ‘ << myints[1] << ‘ ‘ << myints[2] << ‘\n‘; return 0; }
原文:https://www.cnblogs.com/youge-OneSQL/p/9483578.html