Uva 10189 Minesweeper 扫雷游戏
来源:互联网 发布:热网远程监控系统数据 编辑:程序博客网 时间:2024/03/29 19:57
解题思路:这题还是比较简单,找个一个是地雷的位置,然后将从八个方向上的地雷数+1就好了,具体贴上代码。
#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int maxn=105;char map[maxn][maxn];int m,n;//将当前位置的八个方向地雷数加1void cnt(int x,int y) {for(int i=-1; i<=1; i++) {for(int j=-1; j<=1; j++) {int dx=x+i;int dy=y+j;//如果移动到的位置是合法的if(dx>=0&&dx<m&&dy>=0&&dy<n&&map[dx][dy]!='*') {map[dx][dy]+=1;}}}}void solution() {//input mapfor(int i=0; i<m; i++) {gets(map[i]);replace(map[i],map[i]+n,'.','0');}for(int i=0; i<m; i++) {for(int j=0; j<n; j++) {if(map[i][j]=='*') {cnt(i,j);}}}for(int i=0; i<m; i++)puts(map[i]);}int main() {int k=0;while(cin>>m>>n) {cin.get();if(!m&&!n) break;if(k) cout<<"\n";cout<<"Field #"<<++k<<":"<<endl;solution();}return 0;}
阅读全文
0 0
- Uva 10189 Minesweeper 扫雷游戏
- UVA 10189 - Minesweeper(扫雷)
- UVA 10189 - Minesweeper(扫雷)
- UVa Problem 10189 Minesweeper (扫雷)
- UVa Problem 10189 Minesweeper (扫雷)
- UVa Problem 10189 Minesweeper (扫雷)
- 扫雷游戏Minesweeper game
- 529. Minesweeper 扫雷游戏 DFS BFS
- Uva 10189 - Minesweeper
- uva 10189 - Minesweeper
- UVa 10189 - Minesweeper
- uva 10189 - Minesweeper
- uva 10189 Minesweeper
- UVa 10189 Minesweeper (模拟)
- UVa 10189 Minesweeper
- UVa 10189 Minesweeper
- UVa 10189 - Minesweeper
- uva Minesweeper 10189
- Service
- 算法 字符串匹配算法
- Keras学习笔记(一)
- 《二》关注订阅号时发出问候语
- Citrix 相关资料整理
- Uva 10189 Minesweeper 扫雷游戏
- 【Hadoop】HDFS的运行原理
- 数据库第二章 关系数据结构及形式化定义
- 第十八章 并发登录人数控制——《跟我学Shiro》
- 做个网站,建站公司不给你程序源码,没法做SEO,到底是为什么?
- 学好java一定要这样才行!
- 利用JS 事件 与 Cnavas绘图 以及 H5 缓存写的一个手势解锁(二)
- 剑指offer第十题之第十六题(java详解)
- JQuery可拖拽插件:NesTable