生成字符串向量的所有组合
Generating all the Combinations of a vector of strings
我试图解决一些UVA的问题,我想生成字符串数组的所有可能的组合。例如:
string str[]={"abcd","efg","hij"};
所以程序必须输出:
>abcd efg hij
>abcd hij efg
>hij abcd efg
>hij efg abcd
>efg abcd hij
>efg hij abcd
我想你是在寻找STL的next_permutation算法。
应用到你的例子中,它应该看起来像这样:
std::sort (str, str+3);
std::cout << "The 3! possible permutations with 3 elements:n";
do {
std::cout << str[0] << ' ' << str[1] << ' ' << str[2] << 'n';
} while ( std::next_permutation(str, str+3) );
相关文章:
- 检查向量是否具有所有可能的字符组合
- 从向量的向量中删除向量的组合
- 如何得到几个子向量的组合
- 如何组合两个整数向量
- 如果我们从每个 Y 向量中选择一个值,则 X 数字的每个组合都可能
- 在不使用递归的情况下求解所有 2D 字符串向量组合?(C++)
- 字符串向量的有效组合
- 向量的高效组合最小值和平均值计算
- 如何在 Boost.Sprit.Qi 中从向量制作组合的 ascii::string 规则<string>?
- 将多个向量(函数结果)组合到一个使用模板中
- 双重释放或损坏(输出):使用向量的组合算法0x0000000001a880a0***
- 如何沿行组合两个向量?
- 创建多个向量的所有可能组合
- 如何在 c++ 中将集合和数组合并到向量中
- 在C++编程语言中,如何用n个向量长度的所有可能的字符串组合来填充向量
- 在 C++11 中计算字母和单词的双字母组合的 std::线程向量的问题
- 找到两个向量数组的组合,该数组的总和是 c++ 中所有其他组合的最大值
- 如何在C++中组合向量的元素
- c++组合向量(如果它们共享一个数字)
- 这是用组合向量类重载[]的正确方法吗?