编写模式识别'函数以查找特定顺序出现的数字?C++
writing a pattern recognition 'function to find occurrence of numbers in specific order? c++
>我有一个容器,它存储来自源的双精度值,当数字以特定顺序/模式出现时,我需要找到数字的位置。
vector<double> m = {-0.15,0.2,-0.2,-0.1,0.5,-0.15,-0.8,0.35,-0.2,-0.35......nth}
有没有办法找到数字的位置,如果按顺序(按顺序(出现,例如:
m[x] = 0.1 to 0.5 //value of m[x] must between those two values
m[x+1] = 0.35 to 0.7 //anywhere between the range
m[x+2] = -0.1 to 0.1 // "
m[x+3] = 0.0 to.03 // "
std::search
自定义谓词。
您的模式将包含范围,如果 LHS 双精度位于 RHS 范围内,则需要一个返回 true 的自定义二进制谓词。
未经测试的示例:
using Range = std::pair<double,double>;
std::vector<Range> pattern {{0.1, 0.5}, {0.35, 0.7}, {-0.1, 0.1}, {0.0, 0.03}};
auto match = std::search(begin(m), end(m),
begin(pattern), end(pattern),
[](double d, Range r) {
return (r.first < d) && (d < r.second);
});
为您的双重比较等添加适当的 epsilon 等。
相关文章:
- 如何按数字顺序插入链表节点?
- 首先按给定顺序打印所有数字,然后使用 Array 打印所有字符和其他符号
- 如何使用 OpenMP 使线程以相反的顺序写入其数字?
- 删除C++中向量中第一个最小的数字(并保持顺序)
- C/C++ - 用于按顺序打印数字的 sem_t 类型的单个信号量
- 是否有任何内置函数可以检查给定的两个数字在给定整数数组中的顺序是否相同?
- 如何以相反顺序C 打印整数的单个数字
- C 使用转换(绑定)分配数字
- 我不知道如何创建一个以数字/字母顺序打印出我的整数或字符串的程序
- 如何将int分解为数字并以相同的顺序为向量分配数字
- 函数以相反的顺序输出输入问题,并改进算法以解释相等的数字
- 编写模式识别'函数以查找特定顺序出现的数字?C++
- 意外参数通过使用STL数字的顺序
- 使用for循环检查数字的顺序、递减顺序和递增顺序
- 按数字顺序对数字进行排序
- 使用 "For Loop" 按以下顺序显示数字
- 结构化绑定的标识符是否按顺序初始化?
- 随机顺序的连续数字
- 加速变体:绑定顺序中是否有魔力
- OpenGL VBO 绑定顺序