1 条题解

  • 0
    @ 2025-8-27 20:00:42
    #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
    标签
    递交数
    7
    已通过
    3
    上传者