From 6600bd7f2446deb1bf22424d710068027a1c3c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=ED=9B=88?= Date: Wed, 4 Feb 2026 01:38:00 +0900 Subject: [PATCH] =?UTF-8?q?=EC=99=9C=EC=9D=B4=EB=A0=87=EA=B2=8C=20?= =?UTF-8?q?=EC=98=A4=EB=9E=98=EA=B1=B8=EB=A6=AC=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Oliver.swift" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[3\354\260\250] \353\260\251\352\270\210\352\267\270\352\263\241/Oliver.swift" diff --git "a/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[3\354\260\250] \353\260\251\352\270\210\352\267\270\352\263\241/Oliver.swift" "b/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[3\354\260\250] \353\260\251\352\270\210\352\267\270\352\263\241/Oliver.swift" new file mode 100644 index 0000000..aff2ba4 --- /dev/null +++ "b/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[3\354\260\250] \353\260\251\352\270\210\352\267\270\352\263\241/Oliver.swift" @@ -0,0 +1,49 @@ +func solution(_ m: String, _ musicinfos: [String]) -> String { + + // 분 변환 + func toMinute(_ time: String) -> Int { + let t = time.split(separator: ":").map { Int($0)! } + return t[0] * 60 + t[1] + } + + // 반음처리 + func halfStep(_ s: String) -> String { + return s + .replacingOccurrences(of: "C#", with: "c") + .replacingOccurrences(of: "D#", with: "d") + .replacingOccurrences(of: "F#", with: "f") + .replacingOccurrences(of: "G#", with: "g") + .replacingOccurrences(of: "A#", with: "a") + .replacingOccurrences(of: "B#", with: "C") + .replacingOccurrences(of: "E#", with: "F") + } + + let goal = halfStep(m) + var result = "(None)" + var maxTime = -1 + + for info in musicinfos { + let parts = info.split(separator: ",").map { String($0) } + let start = toMinute(parts[0]) + let end = toMinute(parts[1]) + let playTime = end - start + let title = parts[2] + let melody = Array(halfStep(parts[3])) + + if melody.isEmpty { continue } + + var played = "" + for i in 0.. maxTime { + maxTime = playTime + result = title + } + } + } + + return result +}