PC/UVa 110102/10041 Minesweeper
来源:互联网 发布:js 自定义对象方法 编辑:程序博客网 时间:2024/04/30 01:03
这个题不难,但是最后最后会栽倒PE 手里,犯了经验主义错误注意“There must be an empty line between field outputs. ”只在每两个输出矩阵之间有空行,最后不输出空行(所有数据都是一次输入,只要在两个输出矩阵之间含有空行就行,不要求空行的位置一定得在下一次输入之前)
代码:
#include <iostream>
using namespace std;
#define maxnum 105
int num[maxnum][maxnum];
char map[maxnum][maxnum];
int d[8][2]={-1,0,1,0,0,-1,0,1,-1,-1,1,-1,-1,1,1,1};
int main()
{
int n,m,i,j,k,sum;
int x,y;
int t=0;
while(cin>>n>>m)
{
if(!n||!m)
break;
t++;
for(i=0;i<n;i++)
cin>>map[i];
if(t!=1) cout<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(map[i][j]=='.')
{
sum=0;
for(k=0;k<8;k++)
{
x=i+d[k][0];
y=j+d[k][1];
if((x>=0&&x<n)&&(y>=0&&y<m))
{
if(map[x][y]=='*')
sum++;
}
}
num[i][j]=sum;
}
else num[i][j]=-1;
}
}
cout<<"Field #"<<t<<":"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(num[i][j]==-1)
cout<<"*";
else cout<<num[i][j];
}
cout<<endl;
}
}
return 0;
}
/*
输出格式
4 4
*...
....
.*..
....
Field #1:
*100
2210
1*10
1110
3 5
**...
.....
.*...
Field #2:
**100
33200
1*100
0 0
Press any key to continue
*/
- PC/UVa 110102/10041 Minesweeper
- UVa 10189 Problem: Minesweeper (PC 110102)
- PC 110102 Minesweeper 扫雷//水题
- PC 110102 扫雷(Minesweeper)
- uva 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 10189 - Minesweeper
- uva Minesweeper 10189
- uva 10189 Minesweeper
- UVA 10189 Minesweeper
- UVA 10189 -Minesweeper
- JDK自带的native2ascii工具完全揭密
- 在线状态实现
- ruby入门_loop
- android cmd adb命令安装和删除apk应用
- 湖南大学刷新拼音ORCLE
- PC/UVa 110102/10041 Minesweeper
- Android[高级教程] 设计模式之一 解释器模式
- windows组件服务无法启动(即msdtc服务无法启动)
- 三层框架系列:概述
- 在shell中如何判断一个变量是否为空
- RFC2327 - SDP: Session Description Protocol
- 分布式事务
- ruby入门_break
- 【转】学习算法之路