From 6826b5bc95118d628ea5145ca70578132f3471e0 Mon Sep 17 00:00:00 2001 From: JunYoung Date: Tue, 3 Feb 2026 10:32:39 +0900 Subject: [PATCH] =?UTF-8?q?B#,=20E#=20=EB=AA=B0=EB=9E=90=EB=8A=94=EB=8D=B0?= =?UTF-8?q?=20=EC=A7=88=EB=AC=B8=ED=95=98=EA=B8=B0=20=EB=B3=B4=EA=B3=A0=20?= =?UTF-8?q?=ED=92=88..=20=ED=85=8C=EC=BC=80=2034=EB=B2=88=20=EB=AA=BB?= =?UTF-8?q?=EB=84=98=EA=B9=80..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Raven.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/Raven.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/Raven.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/Raven.swift" new file mode 100644 index 0000000..489c24b --- /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/Raven.swift" @@ -0,0 +1,49 @@ +func solution(_ m:String, _ musicinfos:[String]) -> String { + var result = "(None)" + var resultPlayTime = 0 + var resultStartTime = 0 + + for info in musicinfos { + let info = info.components(separatedBy: ",") + let startTime = toInt(info[0]) + let endTime = toInt(info[1]) + let playTime = endTime - startTime + let musicTitle = info[2] + let melody = info[3] + var music = "" + + while music.count < playTime { + music += toShortString(melody) + } + + if music.prefix(playTime).contains(toShortString(m)) { + if playTime > resultPlayTime { + result = musicTitle + resultPlayTime = playTime + resultStartTime = startTime + } else if playTime == resultPlayTime { + if startTime < resultStartTime { + result = musicTitle + resultPlayTime = playTime + resultStartTime = startTime + } + } + } + } + return result +} + +func toInt(_ timeString: String) -> Int { + let components = timeString.components(separatedBy: ":") + return (Int(components[0])! * 60) + Int(components[1])! +} + +func toShortString(_ string: String) -> String { + return string.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") +}