标签:stl中简单算法实例sort()、next_permutation()
STL中简单算法实例sort()、next_permutation()
#include<iostream> #include<string> #include<algorithm> using namespace std; int main() { string letters; cout<<"Enter the letters grouping (quit to quit): "; while(cin>>letters && letters != "quit") { cout<<"Permutations of "<<letters<<endl; sort(letters.begin(),letters.end()); cout<<letters<<endl; while(next_permutation(letters.begin(),letters.end())) cout<<letters<<endl; cout<<"Enter next sequence (quit to quit):"; } cout<<"Done.\n"; return 0; }
结果:
Enter the letters grouping (quit to quit): abc Permutations of abc abc acb bac bca cab cba Enter next sequence (quit to quit):
next_permutation()自动提供排列组合。
STL中简单算法实例sort()、next_permutation()
标签:stl中简单算法实例sort()、next_permutation()
原文地址:http://9320314.blog.51cto.com/9310314/1546277