当前位置:网站首页>Young's matrix to find whether a number exists
Young's matrix to find whether a number exists
2022-06-13 08:10:00 【Stupid little bird learning code】
int FindNum(int arr[3][3],int k,int row,int col)
{
int x = 0;
int y = col - 1;
while((x<=row-1) && (y>=0))
{
if(arr[x][y]>k)
{
y--;
}
else if(arr[x][y]<k)
{
x++;
}
else
{
return 1;
}
}
return 0;
}
// With return subscript
int FindNum_2(int arr[3][3],int k,int* px,int* py)
{
int x = 0;
int y = *py - 1;
while((x<=*px-1) && (y>=0))
{
if(arr[x][y]>k)
{
y--;
}
else if(arr[x][y]<k)
{
x++;
}
else
{
*px = x;
*py = y;
return 1;
}
}
return 0;
}
int main()
{
int arr[3][3] = {
{1,2,3},{4,5,6},{7,8,9}};
// Upper right corner / The lower left element is the key
int k = 7;// The number to find
int x = 3;
int y = 3;
//int ret = FindNum(arr,k,x,y);
// Return type parameter
int ret = FindNum_2(arr,k,&x,&y);
if(ret == 1)
{
printf(" eureka \n");
printf(" Abscissa :%d Ordinate :%d",x+1,y+1);
}
else
{
printf(" Can't find \n");
}
return 0;
}边栏推荐
- Disk C is full? A few simple tips teach you to release and clean up tens of gigabytes of space on the C disk, the most effective way to clean up the C disk
- Dfinity (ICP) identity authentication and ledger quick start-3
- CCNP_ Bt-ospf big experiment (1)
- Web site access excel in IIS
- 19 | establish data path (bottom): instruction + operation =cpu
- Go 接口实现原理【高阶篇】: type _interface struct
- redis面试题
- How to install the bdtab (BD) new tab plug-in in edge browser (Graphic tutorial)
- 【PYTORCH】Expected object of type torch. xxxTensor but found type torch. cuda. xxxTensor(torch0.4.0)
- 基于paddlepaddle的新冠肺炎识别
猜你喜欢

25 | adventure and prediction (IV): it's raining today. Will it rain tomorrow?

免费文件服务器储存技术

Cosmos star application case

C盘爆满?简单几招教你释放、清理C盘几十G空间,最有效的C盘清理方法

基于paddlepaddle的新冠肺炎识别

18 | establish data path (middle): instruction + operation =cpu

Operation of simulated examination platform for examination question bank of G3 boiler water treatment operation certificate in 2022

Local shooting range 2- file upload vulnerability (III) - Network Security

JMeter UDP pressure measurement
Import the robot model built by SolidWorks into ROS
随机推荐
OpenHarmony笔记-----------(一)
实践出真知--你的字节对齐和堆栈认知可能是错误的
Introduction to dfinity (ICP) -1
获取类的属性
SolidWorks修改工程图中文字字体的方法
判断一个字符串是否由另外一个字符串旋转而来
Set implements list search and exclusion
Recommend several books on DBA promotion
Did decentralized digital identity
leetcode 咒语和药水的成功对数
AcWing 1977. 信息中继(基环树,并查集)
ES6 deleting an attribute of an object
[problem record] taberror: inconsistent use of tabs and spaces in indentation
Disk C is full? A few simple tips teach you to release and clean up tens of gigabytes of space on the C disk, the most effective way to clean up the C disk
[MySQL] methods for troubleshooting lock related problems
ERP basic data Huaxia
ERP basic data concept
ERP 基础数据 概念
v-for生成的子组件列表删除第n行出现数据错乱问题
Success logarithm of leetcode spells and potions