地方生活门户网站,wordpress 上传文章,福田区龙岗区发布通告,徐州seo公司CSTL之Map容器 - 数据结构教程 - C语言网 (dotcpp.com)https://www.dotcpp.com/course/118CSTL之Pair类模板 - 数据结构教程 - C语言网 (dotcpp.com)https://www.dotcpp.com/course/119 刷到一个扫雷的题目#xff0c;之前没有玩怎么过扫雷#xff0c;于是我就去玩了玩…CSTL之Map容器 - 数据结构教程 - C语言网 (dotcpp.com)https://www.dotcpp.com/course/118CSTL之Pair类模板 - 数据结构教程 - C语言网 (dotcpp.com)https://www.dotcpp.com/course/119 刷到一个扫雷的题目之前没有玩怎么过扫雷于是我就去玩了玩一玩就凌晨两点直接上瘾好几天哈哈。 言归正传瞅瞅这道编程题不难用pair表示坐标mappairint,int,int关联容器存储各坐标点状态key-2维坐标value-地雷状态0/1然后迭代器遍历map地雷阵计算当前坐标点处四周8个位置的地雷数注意地雷矩阵边缘处的邻近区域的特殊性可以通过map的find()成员函数的返回值鉴定输出。 #includeiostream
#includemap
#includevector
using namespace std;void mineSweeper(const mappairint,int,int sweeper, vectorint sweeper_size){for(auto itsweeper.begin(); it!sweeper.end(); it){// sweeperif(it-second 1){cout*;}// not sweeper, count sweeper_num aroundelse{int sweeper_sum0;for(int i-1; i1; i){for(int j-1; j1; j){int locs_1 it-first.first i;int locs_2 it-first.second j;if(sweeper.find(make_pair(locs_1,locs_2)) ! sweeper.end()){// cout(locs_1,locs_2);sweeper_sum sweeper.find(make_pair(locs_1,locs_2))-second;// coutsweeper_sum;}}}coutsweeper_sum;}if(it-first.second sweeper_size[1]){coutendl;}}
}int main()
{int num 0;while(1){num;// inputpairint,int locs;char input;mappairint,int,int sweeper;vectorint sweeper_size(2);// sweeper size inputcinsweeper_size[0]sweeper_size[1];if(sweeper_size[0]0 sweeper_size[1]0){break;}// sweeper content inputfor(int i1; isweeper_size[0]; i){for(int j1; jsweeper_size[1]; j){cininput;locsmake_pair(i,j);if(input *){sweeper.insert(pairpairint,int,int(locs,1));}else{sweeper.insert(pairpairint,int,int(locs,0));}}}// // debug input// for(auto itsweeper.begin(); it!sweeper.end(); it){// // coutit-first.first,it-first.second:it-secondendl;// coutit-second;// if(it-first.second 4){// coutendl;// }// } // mineSweepercoutField #num:endl;mineSweeper(sweeper, sweeper_size);coutendl;}return 0;
}