【发布时间】:2013-05-21 22:08:52
【问题描述】:
我正在尝试安排井字游戏。所以我有以下代码:
// 5 turns for x if x goes first
std::string moves = "xxxxxoooo";
do {
std::cout << moves << std::endl;
} while ( std::next_permutation(moves.begin(), moves.end()) );
但它只输出一次原始字符串。我假设每个角色都必须是独一无二的。我有什么办法可以做到这一点?
【问题讨论】:
-
尝试从相反的顺序开始,
next_permutation按字典顺序生成它们,而你所拥有的是字典顺序的最后一个。
标签: c++ permutation