intmain(int argc, char *argv[]) { int m, n; scanf("%d %d", &m, &n); int** a = (int**)malloc(sizeof(int*)*m); //二维数组矩阵 int i, j; for (i = 0; i < m; i++) { a[i] = (int*)malloc(sizeof(int)*n); } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &a[i][j]); } }
int count = 0; for (i = 1; i < m - 1; i++) { for (j = 1; j < n - 1; j++) { if (a[i][j] > a[i][j - 1] && a[i][j] > a[i - 1][j] && a[i][j] > a[i][j + 1] && a[i][j] > a[i + 1][j]) { //判断上下左右的值 printf("%d %d %d\n", a[i][j], i + 1, j + 1); count++; } } }
for (i = 0; i < m; i++) { //释放动态二维数组 free(a[i]); a[i] = NULL; } free(a); a = NULL;