#include

#include

#include

#include

using namespace std;

#define N 128

//判断峰值函数

bool isPark(int grid[N][N], int r, int c)

{
if ((grid[r][c]>grid[r-1][c])&& (grid[r][c] > grid[r+1][c])&&

(grid[r][c] > grid[r][c-1])&& (grid[r][c] > grid[r][c+1]))

{
return true;

}

else

{
return false;

}

}

int main()

{
int nrows, ncols;

int map[N][N];

string filename;

ifstream file; //对文件进行操作

cout << “请输入要打开的文件名” << endl;

cin >> filename;

file.open(filename.c_str()); //打开文件

if (file.fail())

{
cout << “打开错误,请进行调试” << endl;

exit(1);

}

//将文件中的数据输入到二维数组中

file >> nrows >> ncols;//从文件中输入行数和列数

if (nrows>N || ncols>N)

{
cout << “网格太大,请调试程序” << endl;

}

for (int i = 0; i < nrows; i++)

{
for (int j = 0; j < ncols; j++)

{
file >> map[i][j];

}

}

//判断并打印峰值的位置

for (int i = 1; i < nrows-1; i++)

{

for (int j = 1; j < ncols-1; j++)

{
if (isPark(map,i ,j))

{
cout << “行” << i << “列” << j << endl;

}

}

}

system(“pause”);

return 0;

}

注解:要将map.txt文件放置在与main.cpp相同的文件夹下面。
文章转自:人工智能之地形导航系统_Java-答学网

作者:答学网,转载请注明原文链接:http://www.dxzl8.com/

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐