30分求助
查看原帖
30分求助
654928
Zjc20120331楼主2022/11/26 08:54

https://www.luogu.com.cn/record/95443725

#include <bits/stdc++.h>
using namespace std;

int l[110][110];
int s[110][110];

void ji(int x, int y){
	for (int i = x-1; i <= x+1; i++){
		for (int j = y-1; j <= y+1; j++){
			if (i != x && j != y){
				s[i][j]++;
			}
		}
	}
}

int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			char c;
			cin >> c;
			if (c == '*'){
				l[i][j] = 1;
			}
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (l[i][j] == 1){
				ji(i, j);
			}
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++)
			if (l[i][j] == 1) cout << '*';
			else cout << s[i][j];
		cout << endl;
	}
	return 0;
} 
2022/11/26 08:54
加载中...