-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16956.cpp
More file actions
75 lines (71 loc) · 1.03 KB
/
16956.cpp
File metadata and controls
75 lines (71 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
73
74
75
// 16956. 늑대와 양
// 2019.09.14
// 구현
#include<iostream>
using namespace std;
char map[502][502];
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
int main()
{
int r, c;
cin >> r >> c;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
cin >> map[i][j];
}
}
bool flag = true;
// 늑대 주변에 양이 있는지 확인
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
if (map[i][j] == 'W')
{
for (int k = 0; k < 4; k++)
{
int x = i + dx[k];
int y = j + dy[k];
// 범위를 벗어남
if (x < 0 || y < 0 || x >= r || y >= c)
{
continue;
}
// 늑대 주변에 양이 있음
if (map[x][y] == 'S')
{
flag = false;
break;
}
}
}
}
}
if (flag)
{
cout << 1 << endl;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
if (map[i][j] == '.')
{
cout << "D";
}
else
{
cout << map[i][j];
}
}
cout << "\n";
}
}
else
{
cout << 0 << endl;
}
return 0;
}