P2670 [NOIP2015 普及組] 掃雷游戲
傳送門
這是一個模擬題,比較簡單,直接放代碼!
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int N = 110;
char a[N][N];
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i ++)
{
char ch = getchar();
for(int j = 1;j <= m;j ++)
{
scanf("%c",&a[i][j]);
}
}
for(int i = 1;i <= n;i ++)
{
for(int j = 1;j <= m;j ++)
{
if(a[i][j] == '*') printf("*");
else
{
int res = 0;
for(int x = max(i - 1,1);x <= n && x <= i + 1;x ++)
for(int y = max(j - 1,1);y <= m && y <= j + 1;y ++)
if(a[x][y] == '*') res ++;
printf("%d",res);
}
}
printf("\n");
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/376046.html
標籤:其他
