1731 Orders 排列

题意:给一字符串,按字典顺序输出由该串字符组成的全部排列。

用STL做,先sort(),后next_permutation()……

代码如下:

  1. #include  <iostream>
  2. #include  <string>
  3. #include  <algorithm>
  4. using namespace std;
  5. int  main ()
  6. {
  7.     string   words;
  8.     
  9.     cin >> words;
  10.         
  11.     sort (words.begin(), words.end());
  12.         
  13.     cout << words << endl;
  14.     
  15.     while ( next_permutation(words.begin(), words.end()) )
  16.     {
  17.         cout << words << endl;
  18.     }
  19.     
  20.     return 0;
  21. }

你可能感兴趣的:(1731 Orders 排列)