C++查找整数是否存在于矩阵的一列中
C++ Find if integer exits in a column of a matrix
如果我有
int x = 5
和
M=|3 4 5||5 2 1||5 6 2|
如何检查特定列是否包含x?所以当我检查第二列时,我会得到false。如果我检查第一列或第三列,我就会得到正确的结果。在MATLab,我会写
如果find(M(:,2)==x)>1disp其他的disp('false')终止
检查x是否在第二列。我想知道c++中是否有类似的方法。
感谢
试试看。
bool colContains(const std::vector<std::vector<int> > &matrix, int x, int col) {
for(int y = 0; y < matrix.size(); y++) {
if(matrix[y].size() < col) continue; //Make sure we don't go out of bounds
if(matrix[y][col] == x) return true;
}
return false;
}
相关文章:
- 查找矩阵C++中每一列和每一行的最小和最大元素
- 如何在C++中获取二维数组中最少的一列数?
- 如何允许用户选择何时停止三列中的每一列的旋转
- 从我的2d数组中的一列返回的字符串值被压缩为一个字符串(在Mac os上打开Windows txt文件)
- 编写所需的代码以创建动态一维整数数组
- 在犰狳立方体中添加一列 1 的有效方法
- 我如何将一组整数集变成C 中的3D矢量
- 在二维向量的每一列中查找最大值
- 只有一列适合其内容大小,而另一列则拉伸
- 如何将字符串形式的日期 ( "Dec 25, 2012" ) 转换为一组整数 (12/25/12)?
- 如何将单独的数组分组在一起(类似于按一列对表进行排序)
- C++ 最后一列中的直方图错误
- 添加两个矩阵会打印一列垃圾数据 c++
- C 特征:通过参考将矩阵的一列传递到函数中
- 仅制作一列qtreewidget可编辑//故障排除
- 如何查找具有一组整数的函数的'max absolute sum'
- 在 QTableView 中仅对一列进行排序,而不对其他列进行排序.独立列
- 按列对CSV文件进行排序,并与C 中的另一列进行比较
- 按变量数组中的列将一组整数从文本文件读入
- C++查找整数是否存在于矩阵的一列中