C++ 矩阵局部极大值查找算法 - 详细解析与代码实现
#include
using namespace std;
const int N = 25;
int a[N][N];
int main() { int m, n; cin >> m >> n; for (int i = 0; i < m; i ++ ) for (int j = 0; j < n; j ++ ) cin >> a[i][j];
int cnt = 0;
for (int i = 1; i < m - 1; i ++ )
for (int j = 1; j < n - 1; j ++ )
if (a[i][j] > a[i - 1][j] && a[i][j] > a[i + 1][j] && a[i][j] > a[i][j - 1] && a[i][j] > a[i][j + 1])
{
cnt ++ ;
printf('%d %d %d
', a[i][j], i + 1, j + 1); }
if (!cnt) puts("None");
return 0;
} 作者:yxc 链接:https://www.acwing.com/activity/content/code/content/1669663/ 来源:AcWing 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
原文地址: https://www.cveoy.top/t/topic/mGEg 著作权归作者所有。请勿转载和采集!