Minesweeper PC/UVa IDs: 110102/10189, Popularity: A,Success rate: high Level: 1

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<iterator>
#include<cstring> using namespace std; int n, m;
char x[101][101]; void calc()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(x[i][j]=='*')
{
putchar('*');
}
else
{ int count=0;
for(int k=-1;k<=1;k++)
for(int l=-1;l<=1;l++)
{
int a,b;
a=i+k;
b=j+l; if(a>=0 && a<n && b>=0 && b<m && x[a][b]=='*')
{
count++;
} }
printf("%d", count);
} }
printf("\n"); }
} int main()
{
int count=0;
while(scanf("%d %d", &n, &m)!=EOF)
{
if(n==0&&m==0)
break;
for(int i=0;i<n;i++)
{
memset(x[i], 0, m);
scanf("%s", x[i]);
} if(count>0)
printf("\n"); count++;
printf("Field #%d:\n", count);
calc();
} return 0;
}
上一篇:[BZOJ]1052 覆盖问题(HAOI2007)


下一篇:前端基础之jQuery入门 01