๋ฌธ์์ด ์ฒ๋ฆฌํ๋ ๋ฌธ์ . ๊ตฌ๋ฆ์ด ์๋ ์๋ฆฌ๋, ์ด๋ฏธ ์ง๋๊ฐ ์๋ฆฌ๋ ์ฒ๋ฆฌํ ํ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ๊ตฌ๋ฆ์ด ์๋ ์๋ฆฌ๋ฅผ ๋ชจ๋ "-1"๋ก ์ด๊ธฐํํ๊ณ ํ๋ฒ๋ ๋ฐฉ๋ฌธํ์ง ์์ ๊ณณ๋ง ์๊ฐ์ ๋ฃ์ผ๋ฉด ๋๋ค.
๋ฌธ์
https://www.acmicpc.net/problem/10709
๋ด๊ฐ ์์ฑํ ์ฝ๋
Swift
let size = readLine()!.split(separator: " ").map { Int(String($0))! }
var board = [[String]]()
for _ in 0..<size[0] {
let line = Array(readLine()!).map { String($0) }
board.append(line)
}
var clouds = [[Int]]()
for i in 0..<size[0] {
for j in 0..<size[1] {
if board[i][j] == "." {
board [i][j] = "-1"
} else {
board[i][j] = "0"
clouds.append([i, j])
}
}
}
var time = 1
while !clouds.isEmpty {
var temp = [[Int]]()
while !clouds.isEmpty {
var cloud = clouds.removeFirst()
cloud[1] += 1
if cloud[1] >= size[1] { // ๊ตฌ๋ฆ์ด ๋ฐ๊นฅ์ผ๋ก ๋ฒ์ด๋ฌ์ ๋
continue
} else { // ๊ตฌ๋ฆ์ด ๋ฐ๊นฅ์ผ๋ก ๋ฒ์ด๋์ง ์์
if board[cloud[0]][cloud[1]] == "-1" { // ํ๋ฒ๋ ๋ฐฉ๋ฌธํ์ง ์์ ๊ณณ
board[cloud[0]][cloud[1]] = "\(time)"
temp.append(cloud)
}
}
}
clouds = temp
time += 1
}
for b in board {
print(b.joined(separator: " "))
}