ネタ元 → 順列生成メソッド
STL/CLRの出番だぜ。
--- myutil.h ---
namespace MyUtil {
public ref class Algrithm {
public:
static bool NextPermutation(String^% str);
};
}
--- myutil.cpp ---
#include <cliext/algorithm>
#include <cliext/vector>
#include "myutil.h"
namespace MyUtil {
bool Algrithm::NextPermutation(String^% str) {
cliext::vector<Char> v(str->ToCharArray());
bool result = cliext::next_permutation(v.begin(),v.end()); // あるもーん
str = gcnew String(v.to_array());
return result;
}
}
--- user.cs ---
using System;
using MyUtil;
class Program {
static void Main(string[] args) {
string str = "ABCD";
do {
Console.WriteLine(str);
} while ( Algrithm.NextPermutation(ref str) );
}
}