为啥有俩过不了 6 9
查看原帖
为啥有俩过不了 6 9
804490
qqqqewdwqew楼主2022/10/23 16:39
#include <stdio.h>
#include <string.h>
char a[1000][1000];
int l, c;
int much(int x, int y) {
	int cnt = 0;
	if (x + 1 <= c) {
		if (a[x + 1][y] == '*') cnt++;
	}
	if (x - 1 >= 0) {
		if (a[x - 1][y] == '*') cnt++;
	}
	if (y - 1 >= 0) {
		if (a[x][y - 1] == '*') cnt++;
	}
	if (y + 1 <= l) {
		if (a[x][y + 1] == '*') cnt++;
	}
	if (x + 1 <= c && y + 1 <= l) {
		if (a[x + 1][y + 1] == '*') cnt++;
	}
	if (x - 1 >= 0 && y - 1 >= 0) {
		if (a[x - 1][y - 1] == '*') cnt++;
	}
	if (x + 1 <= c && y - 1 >= 0) {
		if (a[x + 1][y - 1] == '*') cnt++;
	}
	if (x - 1 >= 0 && y + 1 <= l) {
		if (a[x - 1][y + 1] == '*') cnt++;
	}
	return cnt;
}
int main () {
	scanf("%d%d", &l, &c);
	for (int i = 0; i < l; i++) {
		scanf("%s", a[i]);
	}
	for (int i = 0; i < l; i++) {
		for (int j = 0; j < c; j++) {
			if (a[i][j] != '*') {
				a[i][j] = much(i, j)+48;
			}
		}
	}
	for (int i = 0; i < l; i++) {
		if(i!=l-1) printf("%s\n",a[i]);
		else printf("%s",a[i]);
	}
}
2022/10/23 16:39
加载中...