https://programmers.co.kr/learn/courses/30/lessons/42888
3, 9, 10, 11, 12, 14, 16, 24, 25, 26, 27, 28, 29 실패가 난다.
import Foundation
func solution(_ record:[String]) -> [String] {
var result = [String]()
var dic = [String: String]()
for i in record {
let array = i.split(separator: " ").map{String($0)}
var sentence = ""
if array[0] == "Enter" {
dic.updateValue(array[2], forKey: array[1])
sentence = array[1] + " " + array[0]
result.append(sentence)
} else if array[0] == "Change" {
dic.updateValue(array[2], forKey: array[1])
} else if array[0] == "Leave" {
sentence = array[1] + " " + array[0]
result.append(sentence)
}
}
for (j, v) in result.enumerated() {
let sentences = v.split(separator: " ").map({String($0)})
let id = sentences[0]
let sentence = sentences[1]
result[j] = result[j].replacingOccurrences(of: id, with: dic[id]!)
if sentence == "Enter" {
result[j] = result[j].replacingOccurrences(of: " Enter", with: "님이 들어왔습니다.")
} else if sentence == "Leave" {
result[j] = result[j].replacingOccurrences(of: " Leave", with: "님이 나갔습니다.")
}
}
return result
}
print(solution(["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"]))