unit 38.8

Run Settings
LanguageC
Language Version
Run Command
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int m, n; scanf("%d %d", &m, &n); if (m < 3 || n < 3 || m>10 || n>10) goto EXIT; char** matrix = malloc(sizeof(char*) * m); for (int i = 0; i < m; i++) { matrix[i] = malloc(sizeof(char) * (n + 1)); memset(matrix[i], 0, sizeof(char) * n); } for (int i = 0; i < m; i++) scanf("%s", matrix[i]); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (matrix[i][j] == '*') continue; else { matrix[i][j] = 0; } } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (matrix[i][j] == 0) { for (int y = i - 1; y <= i + 1; y++) { for (int x = j - 1; x <= j + 1; x++) { if (y < 0 || x < 0 || y >= m || x >= n) continue; else { if (matrix[y][x] == '*') matrix[i][j] += 1; else continue; } } } } } } for (int i = 0; i < m; i++) { printf("%s\n", matrix[i]); } EXIT: return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines