2 条题解
-
1Infinity_ LV 8 @ 2024-09-08 12:27:29
#include<iostream> using namespace std; char a[110][110]; int q[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; int main(){ ios::sync_with_stdio(false); int m, n, cnt = 0; cin >> m >> n; for(int i = m+1; i >= 0; i--){ for(int j = n+1; j >= 0; j--)a[i][j] = '?'; } for(int i = 1; i <= m; i++){ for(int j = 1; j <= n; j++)cin >> a[i][j]; } for(int i = 1; i <= m; i++){ for(int j = 1; j <= n; j++){ if(a[i][j] == '?'){ for(int k = 0; k < 8; k++){ if(a[i+q[k][0]][j+q[k][1]] == '*')cnt++; } cout << cnt; cnt = 0; }else cout << '*'; } cout << endl; } return 0; }
-
12023-05-27 20:21:48@
#include<bits/stdc++.h> using namespace std; int n,k,a[110][110],ans,t,m,l=1; char b[110][110]; int main() { cin>>n>>m; for(int i=1;i<=n;i=i+1) for(int j=1;j<=m;j++) cin>>b[i][j]; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(b[i][j]!='*') { if(b[i-1][j-1]=='*')a[i][j]++; if(b[i][j-1]=='*')a[i][j]++; if(b[i+1][j-1]=='*')a[i][j]++; if(b[i+1][j]=='*')a[i][j]++; if(b[i+1][j+1]=='*')a[i][j]++; if(b[i][j+1]=='*')a[i][j]++; if(b[i-1][j+1]=='*')a[i][j]++; if(b[i-1][j]=='*')a[i][j]++; } else a[i][j]=-1; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(a[i][j]!=-1) cout<<a[i][j]; else cout<<"*"; } cout<<endl; } return 0; }//尝试玩一下!!!耗费我很长时间的!!!
- 1