Untitled

Run Settings
LanguageC
Language Version
Run Command
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> int main() { int row, col; scanf("%d %d", &row, &col); char **m = malloc(sizeof(char*)*row); for (int i = 0; i < row; i++) { m[i] = malloc(sizeof(int)*(col+1)); } for (int i = 0; i < row; i++) { scanf("%s", m[i]); } for (int i = 0; i < row+1; i++) { for (int j = 0; j < col; j++) { int sum = 0; if (m[i][j] == '*') printf("*"); else { if ((i+1)<row && m[i+1][j] == '*') sum++; if ((i + 1)<row && m[i+1][j+1] == '*') sum++; if ((i + 1)<row && (j-1)>=0 && (m[i+1][j-1] == '*')) sum++; if (m[i][j+1] == '*') sum++; if ((j - 1) >= 0 && (m[i][j-1] == '*')) sum++; if ((i - 1) >= 0 && m[i-1][j] == '*') sum++; if ((i - 1) >= 0 && m[i-1][j+1] == '*') sum++; if ((i - 1) >= 0 && m[i-1][j-1] == '*') sum++; printf("%d", sum); } } printf("\n"); } for (int i = 0; i < col; i++) free(m[i]); free(m); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines