偵測炸彈
user_3763047219
c_cpp
3 years ago
915 B
4
Indexable
#include <stdio.h> #define MAXSIZE 18 int main() { int R, C; int boom[MAXSIZE][MAXSIZE]={}; int abcount=0,acount=0; int bcount=0; scanf("%d%d", &R, &C); for (int i = 1;i < R+1;i++) { for (int j = 1;j < C+1;j++) { scanf("%d", &boom[i][j]); } } for (int i = 1;i < R+1;i++) { for (int j = 1;j < C+1;j++) { if (boom[i][j] == 5) { acount = 0; for (int k = -1;k < 2;k++) { for (int m = -1;m < 2;m++) { if (boom[i + k][j + m]==5) { acount = acount + 1; } } } if (acount == 1) { for (int n = -1;n < 2;n++) { for (int o = -1;o < 2;o++) { if (boom[i + n][j + o] == 1) { boom[i + n][j + o] = 2; abcount = abcount + 1; } } } } } } } for (int i = 1;i < R + 1;i++) { for (int j = 1;j < C + 1;j++) { if (boom[i][j] == 1) { bcount = bcount + 1; } } } printf("%d %d", abcount,bcount); }
Editor is loading...