algorithm

algorithm

next_permutation

stringや他のコンテナの全ての順列を生成する。

#include <algorithm>
...
string str = "ABCDEF";
do {
  cout << str << endl;
} while(next_permutation(str.begin(), str.end()));

Result:
ABCDEF
ABCDFE
ABCEDF
ABCEFD
...
FEDCBA  (計 6! = 720個の文字列を生成)
最終更新:2013年11月02日 03:42