天天看點

根據字典排序找到下一個由n個不同字元組成的序列

根據字典排序找到下一個由n個不同字元組成的序列。

分析請見http://download.csdn.net/detail/kalium/4322281   

根據字典排序找到下一個由n個不同字元組成的序列
根據字典排序找到下一個由n個不同字元組成的序列
// find next permutation
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main ()
{
string str("3102");

sort(str.begin(), str.end());
do {
    cout << str << endl;
} while (next_permutation(str.begin(), str.end()));
  return 0;
}
           
Output:

0123
0132
0213
0231
0312
0321
1023
1032
1203
1230
1302
1320
2013
2031
2103
2130
2301
2310
3012
3021
3102
3120
3201
3210