题意:给一字符串,按字典顺序输出由该串字符组成的全部排列。
用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;
- }
本文介绍了一种利用C++ STL中的sort()和next_permutation()函数来生成并输出给定字符串所有可能的字典序排列的方法。通过简单的代码示例展示了如何高效地解决此类问题。
468

被折叠的 条评论
为什么被折叠?



