有没有一种 STL 方法可以找到字符串的所有排列,给出一个以 C++ 为单位的大小?
Is there an STL method to find all permutations of strings gives a size in C++?
查找按 C++ 大小指定的字符串的所有排列的最佳方法是什么?我正在从 python 过渡,想知道C++是否有一个内置的可以做到这一点,或者我是否必须从头开始实现它。在Python中,我只会做
import itertools
print(list(itertools.permutations(string,size))
这是我尝试模拟的功能。任何帮助将不胜感激,除了没有大小参数next_permutations之外,真的找不到任何东西。
不仅仅是 STL,而且非常简单:
std::string s = ...;
std::sort(s.begin(), s.end()); // to know when you've been through all permutations
std::vector<std::string> v; // v.reserve(boost::math::factorial(s.size());
do {
v.push_back(s); // or process in-place
} while (std::next_permutation(s.begin(), s.end());
相关文章:
- 重新排列单线以形成闭合多边形?
- 是否可以定义一个以向量<T>作为值的unordered_map?
- 有没有一种 STL 方法可以找到字符串的所有排列,给出一个以 C++ 为单位的大小?
- 我是 C++ 的新手,我试图调用 make 一个以 2 个类作为其参数的类构造函数
- 我怎么能有一个以2D数组为参数的函数,而数组有一个我想更改的参数/维度
- 最大数量.给定一个非负整数列表,排列它们以使它们形成最大的数字
- llvm 调用一个以 char * 作为参数的外部函数
- 我不知道如何创建一个以数字/字母顺序打印出我的整数或字符串的程序
- 如何构造一个以可变参数指针函数作为成员的类?
- C++从文件中读取不同类型的数据,直到有一个以数字开头的字符串
- Rcpp:按另一个向量的顺序重新排列一个向量
- 如何创建一个以键为输入并在C++std:map中查找值的模板函数
- 努力理解一个以十六进制、十进制、bin 和 dec 计算数字总和的程序
- 它如何排列单词以使用 qsort 和字符串
- 创建一个以存储线程并调用它们的类
- C 按顺序排列一个指针阵列
- std::string::c_str() 是否总是返回一个以 null 结尾的字符串
- 如何生成一个以非null结尾的c字符串
- 如何为链接列表节点定义一个以指针为模板类型的模板类
- 设计一个以统一方式返回多个接口的类