【1122】简单鞍点

来源:互联网 发布:杨虎城 蒋介石 知乎 编辑:程序博客网 时间:2024/06/04 20:03

描述:

矩阵中比上下两个数都大且比左右两个数都小数称为“鞍点”。求输入的矩阵中鞍点的个数。
In matrix the number who is bigger then the upper and lower two numbers, andsmaller 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 mrows 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

#include<stdio.h>int main(){int m,n,count=0;scanf("%d%d",&m,&n);int f[m][n],i,j;for(i=0;i<m;i++){for(j=0;j<n;j++){scanf("%d",&f[i][j]);}}for(i=1;i<m-1;i++){for(j=1;j<n-1;j++){if(f[i][j]>f[i-1][j]&&f[i][j]>f[i+1][j]&&f[i][j]<f[i][j-1]&&f[i][j]<f[i][j+1])count=count+1;}}printf("%d\n", count);return 0;}