当前位置:网站首页>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;
}
边栏推荐
- 钉钉小程序如何隐藏tab
- How to hide tabs in nailing applet
- 钉钉小程序 父子传参数对象 子组件页面不更新?
- Dfinity (ICP) identity authentication and ledger quick start-3
- 中小型照明灯饰行业如何利用数字化转型突出重围?
- Overview of cross chain protocol IBC
- 18 | establish data path (middle): instruction + operation =cpu
- MySQL: regexp_ replace
- Examination question bank and simulation examination for special operation certificate of safety management personnel of hazardous chemical business units in 2022
- 口碑好的食材配送信息化管理系统怎么样?
猜你喜欢
Selenium reports an error deprecationwarning: executable_ path has been deprecated, please pass in a Service object
Overall process analysis of account book operation in fabric0.6
中小型照明灯饰行业如何利用数字化转型突出重围?
CCNP_ BT static routing
本地靶场2-文件上传漏洞(三)-网络安全
22 | adventure and prediction (I): hazard is both "danger" and "opportunity"
[redis problem] record a big key problem handling
ERP basic data concept
2022年危险化学品经营单位安全管理人员特种作业证考试题库及模拟考试
Detailed explanation of digital certificate and Ca
随机推荐
Detailed explanation of digital certificate and Ca
【clickhouse专栏】基础数据类型说明
Overview of cross chain protocol IBC
C盘爆满?简单几招教你释放、清理C盘几十G空间,最有效的C盘清理方法
【深度学习】:《PyTorch入门到项目实战》(十二)卷积神经网络:填充(padding)和步幅(stride)
Motiko basic syntax in dfinity (ICP) -8
【博弈论-完全信息静态博弈】 Nash均衡
25 | adventure and prediction (IV): it's raining today. Will it rain tomorrow?
Basic operation of dfinity (ICP) development-4
Data disorder occurs when the n-th row of the subcomponent list generated by V-for is deleted
19 | establish data path (bottom): instruction + operation =cpu
钉钉小程序如何隐藏tab
有什么好的管理软件来解决茶叶批发商面临的难题
Unity 退出编辑器模式
Redis interview questions
18 | establish data path (middle): instruction + operation =cpu
Cosmos star application case
[complete information static game characteristics of Nash equilibrium]
21 | pipeline oriented instruction design (Part 2): How did Pentium 4 fail?
MySQL summary