简单鞍点

描述:

矩阵中比上下两个数都大且比左右两个数都小数称为“鞍点”。求输入的矩阵中鞍点的个数。
In matrix the number who is bigger then the upper and lower two numbers, and smaller then the left and right two numbers, called "saddle point". count input matrix saddle-point number.

输入:

输入的第一行是两个整数m、n(2<n,m<100),代表矩阵有m行n列;
接下来的m行每行有n个正整数。
input two integers m and n (2<n,m<100), which represents a matrix of m rows n columns;
Next m lines each line have n positive integer.

输出:

输出鞍点的个数。格式是printf("%d\n", count);
Output the number of the saddle-point

输入样例:

3 4 1 2 13 4 6 5 8 7 4 3 12 1

输出样例:

1

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
 int m,n,count,x,y;
 cin>>m>>n;
 int A[m][n];
 count=0;
 for(x=0;x<m;x++)
 {
  for(y=0;y<n;y++)
  {
   cin>>A[x][y];
  }
 }
 for(x=1;x<m-1;x++)
 {
  for(y=1;y<n-1;y++)
  {
   if(A[x][y]>A[x+1][y]&&A[x][y]>A[x-1][y]&&A[x][y]<A[x][y+1]&&A[x][y]<A[x][y-1])
   {
    count=count+1;
   }
  }
 }
 printf("%d\n",count);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值