728x90
[Swift] 프로그래머스 오픈채팅방(lv. 2)
1. 문제
https://school.programmers.co.kr/learn/courses/30/lessons/42888
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
2. 접근
3. 코드
import Foundation
func solution(_ record:[String]) -> [String] {
var result = [[String]]()
var userList: Dictionary = [String : String]()
for i in record {
let temp = i.split(separator: " ").compactMap({ String($0) })
switch temp[0] {
case "Enter":
userList[temp[1]] = temp[2]
result.append([temp[1], "님이 들어왔습니다."])
case "Leave":
result.append([temp[1], "님이 나갔습니다."])
case "Change":
userList[temp[1]] = temp[2]
default:
break
}
}
for (index, i) in result.enumerated() {
result[index][0] = userList[i[0]]!
}
return result.compactMap({ $0.joined() })
}
728x90
'Problem Solving' 카테고리의 다른 글
[Swift] 프로그래머스 피로도(lv. 2) (0) | 2023.04.08 |
---|---|
[Swift] 프로그래머스 [3차] n진수 게임(lv. 2) (0) | 2023.04.07 |
[Swift] 프로그래머스 [3차] 압축(lv. 2) (0) | 2023.04.04 |
[Swift] 프로그래머스 연속 부분 수열 합의 개수(lv. 2) (0) | 2023.04.03 |
[Swift] 프로그래머스 타겟 넘버(lv. 2) (0) | 2023.04.01 |
댓글