描述:
矩阵中比上下两个数都大且比左右两个数都小数称为“鞍点”。求输入的矩阵中鞍点的个数。
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);
}