码迷,mamicode.com
首页 > 其他好文 > 详细

程序员代码面试指南: 数学计算 在行列都排好序的矩阵中找指定的数

时间:2019-10-14 10:38:32      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:turn   row   end   namespace   style   int   ret   ace   std   

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    int a[n][m];
    for(int i = 0;i < n;++i)
        for(int j = 0;j < m; ++j)
        {
           cin >> a[i][j];
        }
    int x ;
    int col = m - 1;
    int row = 0;
    while(row < n && col > -1)
    {
        if(k == a[row][col])
        {
            cout  << "Yes"<< endl;
            return 0;
        }
        else if(k > a[row][col])
            row++;
        else 
            col--;
    }
    cout << "No" << endl;
}

 

程序员代码面试指南: 数学计算 在行列都排好序的矩阵中找指定的数

标签:turn   row   end   namespace   style   int   ret   ace   std   

原文地址:https://www.cnblogs.com/Jawen/p/11669874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!