From c8bbc06295db86ec1dffa9e9ba053a52bf5155c3 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Sat, 25 Apr 2026 14:47:38 +0900 Subject: [PATCH 1/2] Create liv.swift --- .../liv.swift" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "WEEK12/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260/liv.swift" diff --git "a/WEEK12/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260/liv.swift" "b/WEEK12/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260/liv.swift" new file mode 100644 index 0000000..45704ef --- /dev/null +++ "b/WEEK12/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260/liv.swift" @@ -0,0 +1,71 @@ +// 백준 - 14499 주사위 굴리기 + +let line = readLine()!.split(separator: " ").compactMap { Int($0) } +let n = line[0]; let m = line[1]; let x = line[2]; let y = line[3] + +var map = [[Int]]() +for _ in 1...n { map.append(readLine()!.split(separator: " ").compactMap { Int($0) }) } + +let orders = readLine()!.split(separator: " ").compactMap { Int($0) } +let directions = [(0, 1), (0, -1), (-1, 0), (1,0)] + +var dice = [Int](repeating: 0, count: 6) +var coord: (r: Int, c: Int) = (x, y) +var result = [String]() + +for order in orders { + // 지도 다음 칸 찾기 + let direction = directions[order-1] + let next: (r: Int, c: Int) = (coord.r+direction.0, coord.c+direction.1) + + // 다음 칸의 숫자 확인 + guard next.r >= 0 && next.r < n && next.c >= 0 && next.c < m else { continue } + coord = next + + // 주사위 굴리기 + roll(order) + + if map[coord.r][coord.c] == 0 { + map[coord.r][coord.c] = dice[5] + } else { + dice[5] = map[coord.r][coord.c] + map[coord.r][coord.c] = 0 + } + + result.append(String(dice[0])) +} + +print(result.joined(separator: "\n")) + +func roll(_ order: Int) { + let temp = dice + + switch order { + case 1: + dice[0] = temp[3] + dice[2] = temp[0] + dice[5] = temp[2] + dice[3] = temp[5] + + case 2: + dice[0] = temp[2] + dice[3] = temp[0] + dice[5] = temp[3] + dice[2] = temp[5] + + case 3: + dice[0] = temp[4] + dice[1] = temp[0] + dice[5] = temp[1] + dice[4] = temp[5] + + case 4: + dice[0] = temp[1] + dice[4] = temp[0] + dice[5] = temp[4] + dice[1] = temp[5] + + default: + break + } +} From c87b3601ac30d312f6edba7c9a40bb2a03b44cf7 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Sat, 25 Apr 2026 15:12:28 +0900 Subject: [PATCH 2/2] Create liv.swift --- .../liv.swift" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "WEEK12/\353\260\261\354\244\200_14890_\352\262\275\354\202\254\353\241\234/liv.swift" diff --git "a/WEEK12/\353\260\261\354\244\200_14890_\352\262\275\354\202\254\353\241\234/liv.swift" "b/WEEK12/\353\260\261\354\244\200_14890_\352\262\275\354\202\254\353\241\234/liv.swift" new file mode 100644 index 0000000..861c651 --- /dev/null +++ "b/WEEK12/\353\260\261\354\244\200_14890_\352\262\275\354\202\254\353\241\234/liv.swift" @@ -0,0 +1,52 @@ +// 백준 - 14890 경사로 + +let nl = readLine()!.split(separator: " ").compactMap { Int($0) } +let n = nl[0]; let l = nl[1] +var map = [[Int]]() +for _ in 0.. Bool { + var used = [Bool](repeating: false, count: n) + + for i in 0..= n { return false } + for j in i+1...end { + if used[j] { return false } + if line[j] != line[i+1] { return false } + used[j] = true + } + } + + else { return false } + } + return true +}