假定左上角是[0][0],那么向下移动,则行号加 1;向右移动,则列号加 1,通过操作数组下标位置操作,来确定位置,再与周围 8 个邻节点比较即可确定最大值,具体操作看实例:

map.txt ( 将.txt文件放入与main.cpp文件同级目录 )
6 7
5039 5127 5238 5259 5248 5310 5299
5150 5392 5410 5401 5320 5820 5321
5290 5560 5490 5421 5530 5831 5210
5110 5429 5430 5411 5459 5630 5319
4920 5129 4921 5821 4722 4921 5129
5023 5129 4822 4872 4794 4862 4245
main.cpp
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
using namespace std;
#define N 42
bool isPeak(const double grid[N][N], int i, int j);
bool isValley(const double grid[N][N], int i, int j);
void extremes(const double grid[N][N], in

本文介绍如何在C++中处理二维数组,通过遍历并比较每个元素与其周围8个邻节点的值,找出数组中的最大值及其坐标。实践案例包括读取地图数据并进行操作。

3465

被折叠的 条评论
为什么被折叠?



