#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()自动提供排列组合。
时间: 2024-11-07 20:42:57