-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeup-1524.cpp
More file actions
50 lines (38 loc) · 795 Bytes
/
Codeup-1524.cpp
File metadata and controls
50 lines (38 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
int map[9][9];
int w = 9;
int h = 9;
int Correct(int val, int min, int max)
{
if(val < min)
val = min;
if(val > max)
val = max;
return val;
}
int GetNeighborMineNum (int x, int y)
{
if(map[y][x] == 1)
return -1;
int left = Correct(x-1, 0, 8);
int right = Correct(x+1, 0, 8);
int top = Correct(y-1, 0, 8);
int bottom = Correct(y+1, 0, 8);
int mineNum = 0;
for(int countY=top; countY<=bottom; ++countY)
for(int countX=left; countX<=right; ++countX)
mineNum += map[countY][countX];
return mineNum;
}
int main ()
{
int x, y;
for(int countY=0; countY<9; ++countY)
for(int countX=0; countX<9; ++countX)
scanf("%d", &(map[countY][countX]));
scanf("%d%d", &y, &x);
--x;
--y;
printf("%d", GetNeighborMineNum(x, y));
return 0;
}