-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1996.cpp
More file actions
72 lines (68 loc) · 1.03 KB
/
1996.cpp
File metadata and controls
72 lines (68 loc) · 1.03 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 1996. 지뢰 찾기
// 2019.08.16
// 구현
#include<iostream>
#include<string>
using namespace std;
int dx[8] = { -1,-1,-1,0,0,1,1,1 };
int dy[8] = { -1,0,1,1,-1,-1,0,1 };
char map[1001][1001];
char copyMap[1001][1001];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
for (int j = 0; j < s.size(); j++)
{
map[i][j] = s[j];
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (map[i][j] == '.')
{
int cnt = 0;
for (int k = 0; k < 8; k++)
{
int x = i + dx[k];
int y = j + dy[k];
if (x < 0 || y < 0 || x >= n || y >= n)
{
continue;
}
if (map[x][y] - '0' > 0 && map[x][y] - '0' <= 9)
{
cnt += map[x][y] - '0';
}
}
if (cnt > 9)
{
copyMap[i][j] = 'M';
}
else
{
copyMap[i][j] = cnt+'0';
}
}
else
{
copyMap[i][j] = '*';
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << copyMap[i][j];
}
cout << "\n";
}
return 0;
}