人工智能之地形导航系统

#include<iostream>

#include<Windows.h>

#include<string>

#include<fstream>

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;

}

05e7f478c49d4752a95ed4d1bf814322.png

 63fe1ea4e2a64e2eaacfa2eb972881f6.png

 注解:要将map.txt文件放置在与main.cpp相同的文件夹下面。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值