-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path[프로그래머스] 박정아_거리두기 확인하기.swift
88 lines (80 loc) · 3.05 KB
/
[프로그래머스] 박정아_거리두기 확인하기.swift
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
76
77
78
79
80
81
82
83
84
85
86
87
import Foundation
func solution(_ places:[[String]]) -> [Int] {
var answer: [Int] = []
for place in places {
let place = place.map{ Array($0) }
var distancing = true
for i in 0..<5 {
for j in 0..<5 {
if place[i][j] == "P" {
if i - 1 >= 0 {
if place[i - 1][j] == "P" {
distancing = false
break
}
if place[i - 1][j] == "O" {
if i - 2 >= 0 && place[i - 2][j] == "P" {
distancing = false
break
}
if j - 1 >= 0 && place[i - 1][j - 1] == "P" {
distancing = false
break
}
if j + 1 < 5 && place[i - 1][j + 1] == "P" {
distancing = false
break
}
}
}
if i + 1 < 5 {
if place[i + 1][j] == "P" {
distancing = false
break
}
if place[i + 1][j] == "O" {
if i + 2 < 5 && place[i + 2][j] == "P" {
distancing = false
break
}
if j - 1 >= 0 && place[i + 1][j - 1] == "P" {
distancing = false
break
}
if j + 1 < 5 && place[i + 1][j + 1] == "P" {
distancing = false
break
}
}
}
if j + 1 < 5 {
if place[i][j + 1] == "P" {
distancing = false
break
}
if place[i][j + 1] == "O" {
if j + 2 < 5 && place[i][j + 2] == "P" {
distancing = false
break
}
if i - 1 >= 0 && place[i - 1][j + 1] == "P" {
distancing = false
break
}
if i + 1 < 5 && place[i + 1][j + 1] == "P" {
distancing = false
break
}
}
}
}
}
}
if distancing {
answer.append(1)
} else {
answer.append(0)
}
}
return answer
}