c++编程
来源:互联网 发布:康佳电视的网络功能 编辑:程序博客网 时间:2024/06/11 14:50
//题目:
//在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。
//请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
#include<iostream>
using namespace std;bool Find(int *matrix, int rows, int columns, int number); //函数声明
int main()
{
int a[4][4];
/*输入二维数组,每一行都从左到右递增排序, 每一列都从上到下递增排序*/
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
{
cin >> a[i][j];
}
// 输出二维数组
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
cout<<Find(&a[0][0], 4, 4, 7)<<endl; //调用函数
return 0;
}
//函数定义
bool Find(int *matrix, int rows, int columns, int number)
{
bool found = false;
if (matrix != NULL && rows > 0 && columns > 0)
{
int row = 0;
int column = columns - 1;
while (row < rows && column >= 0)
{
if (matrix[row * columns + column] == number)
{
found = true;
break;
}
else if (matrix[row * columns + column] > number)
--column;
else
++row;
}
}
return found;
}
0 0
- C编程
- c编程
- C编程
- c编程
- C编程
- c编程
- C编程
- c编程
- c编程
- C编程
- C编程
- 【C/C++】CGI编程
- Linux C编程---网络编程
- Linux C编程网络编程
- Linux C编程---网络编程
- linux c编程--文件系统编程
- Linux C编程---网络编程
- linux-C编程-网络编程
- 团队沟通时的逻辑的清晰表达
- 左旋转字符窜
- 11.23
- No configuration found for the specified action: 'user' in namespace: ''
- Ubuntu14.04全分布式安装Hadoop 2.7.2(一)创建用户组
- c++编程
- 小笔记之mysql数据库
- 将字符串S1中任何与字符串S2中匹配的字符都删除,实现函数squeeze(s1,s2).
- VC中int,char,char*,const char*,string等类型转换(转载)
- LeetCode 299. Bulls and Cows
- SwipeRefush
- c语言当中出现的问题
- 项目中遇到的问题:去重以及webview关闭后有声音办法
- 分离码的实现