模拟题解
2026-08-19 11:13:59
发布于:四川
3阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int a[505][505];
int f(int x,int y){
int cnt=0;
if(a[x][y]-1){
return -1;
}
if(a[x+1][y]-1)cnt++;
if(a[x-1][y]-1)cnt++;
if(a[x][y+1]-1)cnt++;
if(a[x][y-1]-1)cnt++;
if(a[x+1][y-1]-1)cnt++;
if(a[x-1][y+1]-1)cnt++;
if(a[x+1][y+1]-1)cnt++;
if(a[x-1][y-1]-1)cnt++;
return cnt;
}
int main(){
cin>>n>>m>>k;
while(k--){
int x1,y1;
cin>>x1>>y1;
a[x1][y1]=-1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int t=f(i,j);
if(t-1){
cout<<"*"<<' ';
}else {
cout<<t<<' ';
}
}
cout<<'\n';
}
return 0;
}
这里空空如也






有帮助,赞一个