2 条题解
-
0
#include<bits/stdc++.h> using namespace std; int n,m,a[105][105],b[105][105]; char x; int main() { cin>>n>>m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>x; if(x=='') { a[i][j]=1; b[i][j]=1; } else { a[i][j]=0; } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(!a[i][j])a[i][j]+=b[i+1][j]+b[i-1][j]+b[i][j+1]+b[i][j-1]+b[i+1][j+1]+b[i+1][j-1]+b[i-1][j+1]+b[i-1][j-1]; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(b[i][j]) { cout<<''; } else { cout<<a[i][j]; } } cout<<endl; } }
-
0
#include <bits/stdc++.h> using namespace std; const int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}; const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; char g[101][101]; int n, m, cnt; int main(void) { cin >> n >> m; for (int i = 0;i < n;++i) { for (int j = 0;j < m;++j) { cin >> g[i][j]; } } for (int i = 0;i < n;++i) { for (int j = 0;j < m;++j) { if (g[i][j] != '*') { cnt = 0; for (int k = 0;k < 8;++k) { if (g[i + dx[k]][j + dy[k]] == '*') { cnt++; } } cout << cnt; } else { cout << '*'; } } if (i != n - 1) cout << '\n'; } return 0; }注意清零
- 1
信息
- ID
- 3
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 10
- 标签
- 递交数
- 9
- 已通过
- 3
- 上传者