题目描述
在一个 nn 行 mm 列的方格图上有一些位置有地雷,另外一些位置为空。
请为每个空位置标一个整数,表示周围八个相邻的方格中有多少个地雷。
输入描述
输入的第一行包含两个整数 n, mn,m。
第 22 行到第 n + 1n+1 行每行包含 mm 个整数,相邻整数之间用一个空格分隔。如果对应的整数为 00,表示这一格没有地雷。如果对应的整数为 11,表示这一格有地雷。
其中,1 \leq n, m \leq 1001≤n,m≤100 分钟后还是在当天。
输出描述
输出 nn 行,每行 mm 个整数,相邻整数之间用空格分隔。
对于没有地雷的方格,输出这格周围的地雷数量。对于有地雷的方格,输出 99。
输入输出样例
示例 1
输入
3 4
0 1 0 0
1 0 1 0
0 0 1 0
输出
2 9 2 1
9 4 9 2
1 3 9 2
# include<bits/stdc++.h>
using namespace std;
int ans[110][110],m[110][110],ll,rr;
int main(){
int a,b,c;
cin>>a>>b;
for(int t=1;t<=a;t++){
for(int x=1;x<=b;x++){
cin>>m[t][x];
}
}
for(int t=1;t<=a;t++){
for(int x=1;x<=b;x++){
if(m[t][x]==0){
for(int ll=t-1;ll<=t+1;ll++){
for(int rr=x-1;rr<=x+1;rr++){
if(m[ll][rr]==1){
ans[t][x]++;
}
}
}
}else{
ans[t][x]=9;
}
}
}
for(int t=1;t<=a;t++){
for(int i=1;i<=b;i++){
cout<<ans[t][i]<<" ";
}
cout<<"\n";
}
}
运行限制
- 最大运行时间:1s
- 最大运行内存: 128M
总通过次数: 736 | 总提交次数: 761 | 通过率: 96.6%
难度: 标签: 模拟, 暴力, 2021, 模拟赛