提交记录 #264
提交时间:2024-11-18 21:17:52
语言:c
状态:Unaccepted
编译情况:编译成功
code.c: In function ‘main’:
code.c:64:26: warning: passing argument 2 of ‘count_mines’ from incompatible pointer type [-Wincompatible-pointer-types]
64 | count_mines(map, result, n, m);
| ^~~~~~
| |
| char (*)[100]
code.c:7:50: note: expected ‘int (*)[100]’ but argument is of type ‘char (*)[100]’
7 | void count_mines(char map[MAX_N_M][MAX_N_M], int result[MAX_N_M][MAX_N_M], int n, int m) {
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
固定测试点#1:
固定测试点#2:
附加测试点暂不可用
40【游戏】扫雷:如此传统的游戏,你现在就可以动手来开发
#include <stdio.h>
#include <stdlib.h>
#define MAX_N_M 100
void count_mines(char map[MAX_N_M][MAX_N_M], int result[MAX_N_M][MAX_N_M], int n, int m) {
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (map[i][j] == '.') {
int count = 0;
for (int k = 0; k < 8; k++) {
int ni = i + dx[k];
int nj = j + dy[k];
if (ni >= 0 && ni < n && nj >= 0 && nj < m && map[ni][nj] == '*') {
count++;
}
}
result[i][j] = count + '0'; // Convert count to character
} else {
result[i][j] = '*'; // Keep '*' for mine cells
}
}
}
}
void print_field(char result[MAX_N_M][MAX_N_M], int n, int m, int field_num) {
printf("Field #%d:\n", field_num);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%c", result[i][j]);
}
printf("\n");
}
printf("\n");
}
int main() {
int n, m;
char map[MAX_N_M][MAX_N_M];
char result[MAX_N_M][MAX_N_M];
int field_num = 1;
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0) {
break;
}
for (int i = 0; i < n; i++) {
scanf("%s", map[i]);
}
// Initialize result matrix with empty characters
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
result[i][j] = '\0';
}
}
count_mines(map, result, n, m);
print_field(result, n, m, field_num);
field_num++;
}
return 0;
}