《剑指offer》面试题3(2)
来源:互联网 发布:意大利工业知乎 编辑:程序博客网 时间:2024/05/16 08:10
#include <iostream>#include <cstdio>using namespace std;const int maxn = 100;int a[maxn*maxn],n,m;bool isInArray(int* matrix, int rows, int columns, int number);int main(){ while(true) { scanf("%d %d",&n,&m); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { scanf("%d",&a[i*m+j]); } } int number,data; scanf("%d",&number); for(int i=0;i<number;i++) { scanf("%d",&data); cout<<(isInArray(a,n,m,data)?"Yes":"No")<<endl; } } return 0;}bool isInArray(int* matrix, int rows, int columns,int number){ if(matrix == NULL || rows<=0 || columns<=0) return false;//排除非法数据 int row = 0; int column = columns-1; while(row<rows && column>=0) { if(matrix[row*columns+column] == number) //找到number return true; else if(matrix[row*columns+column] < number) //右上角的元素小于number,删除最上面的一行 row++; else //右上角的元素大于number,删除最右面的一列 column--; } return false;}
0 0
- 《剑指offer》面试题3(2)
- 剑指Offer(面试题3~5)
- 剑指offer面试题3
- 《剑指offer》面试题3
- 剑指offer 面试题3
- 剑指offer面试题3
- 【面试题】剑指offer 3
- 剑指offer 面试题3
- 剑指offer 面试题2
- 【面试题】剑指offer 2
- 剑指Offer(第2版) 面试题3、面试题4,Java实现
- 剑指offer 面试题
- 剑指offer面试题
- 《剑指Offer》面试题:1+2+3+...+n
- 剑指offer--面试题46:求1+2+3+...+n
- 剑指offer-面试题46-求1+2+3+...+n
- 【剑指Offer】面试题46:求1+2+3+...+n
- 二维数组中的查找(剑指offer面试题3)
- log file sync
- POJ 3041Asteroids(二分图最大匹配)
- [Unity3D]Unity3D游戏开发之回合制游戏原型的实现
- Sublime Text 使用技巧
- final关键字
- 《剑指offer》面试题3(2)
- 统治世界的十大算法
- 应届毕业生三方协议
- 网络编程socket基本API详解
- ios视图切换效果
- 《剑指offer》面试题4(合并数组)
- 黑马程序员--Java异常处理
- 《剑指offer》面试题4(替换空格)
- linux 常用命令