题意:给一字符串,按字典顺序输出由该串字符组成的全部排列。
用STL做,先sort(),后next_permutation()……
代码如下:
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- int main ()
- {
- string words;
- cin >> words;
- sort (words.begin(), words.end());
- cout << words << endl;
- while ( next_permutation(words.begin(), words.end()) )
- {
- cout << words << endl;
- }
- return 0;
- }