Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MuchanKim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
| 1μ°¨μ‹œ | 2025.03.29 | κ΅¬ν˜„ | [개미](https://www.acmicpc.net/problem/3048)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/3|
| 2μ°¨μ‹œ | 2025.04.11 | μ—λΌν† μŠ€ν…Œλ„€μŠ€μ˜μ±„ | [μ†Œ-λ‚œλ‹€!](https://www.acmicpc.net/problem/19699)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/10|
| 3μ°¨μ‹œ | 2025.04.29 | 그리디 | [μ•Œλ°”μƒ κ°•ν˜Έ](https://www.acmicpc.net/problem/1758)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/14|
| 4μ°¨μ‹œ | 2025.05.11 | κ΅¬ν˜„ | [μ˜€ν”ˆμ±„νŒ…λ°©](https://school.programmers.co.kr/learn/courses/30/lessons/42888)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/20|

---
59 changes: 59 additions & 0 deletions MuchanKim/κ΅¬ν˜„/μ˜€ν”ˆμ±„νŒ…λ°©.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Foundation

typealias UserID = String
typealias Nickname = String
Comment on lines +3 to +4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typealias λ₯Ό μ‚¬μš©ν•˜μ…¨κ΅°μš” !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옹 typealiasλŠ” μƒκ°μ•ˆν•˜κ³  κ΅¬ν˜„ν–ˆλŠ”λ° 이것도 μ’‹λ„€μš”!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typealias fxxking Swiftful!


enum Action: String {
case enter = "Enter"
case leave = "Leave"
case change = "Change"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•— μ €λŠ” μ—¬κΈ°μ„œ μ—΄κ±°ν˜• μ“Έ 생각 λͺ» ν•˜κ³  if문으둜 μΌλŠ”λ° 보기 μ’‹μ•„μš” πŸ‘πŸ»

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„λ‹ˆ γ…‹γ…‹γ…‹ 걍 각각 λͺ…λ Ήμ–΄ recordλ‚˜λˆ„κ³  λ‹΄κ³  μƒνƒœκΉŒμ§€μ•ˆν•˜κ³  걍 λ“€μ–΄μ˜€λ©΄ λ“€μ–΄μ˜€λŠ”λ°λ‘œ λ‚˜κ°€λ©΄ λ‚˜κ°€λŠ”λ°λ‘œ μ°μ–΄μ£ΌλŠ” κ±°μ˜€λ„€μš” γ…‹γ…‹γ…‹ ν•˜.... κΈ€λ‘œλ‹ˆ μ½”λ“œλ„ 잘 λ³΄κ³ κ°‘λ‹ˆλ‹€.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헐 enum을 μ΄λ ‡κ²Œμ¨μ„œ ν•˜λŠ”κ²Œ μžˆμ—ˆλ„€μš” if문으둜 λŒ€μΆ© ν–ˆλŠ”λ° μ’‹κ΅°μš”!

}

func createMessage(_ action: Action, _ userId: UserID, _ userDict: [UserID: Nickname]) -> String? {
Copy link
Collaborator

@bishoe01 bishoe01 May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 μ΄λ ‡κ²Œ μ²˜λ¦¬ν•΄μ£ΌλŠ” ν•¨μˆ˜λ₯Ό λ§Œλ“€κΈ΄ν–ˆλŠ”λ°, μ €λŠ” 이걸 ν•œ 번 더 좜λ ₯을 μœ„ν•œ 배열에 λ‹΄μ•„μ£Όκ³  해결을 ν•˜λ‹€λ³΄λ‹ˆ λ²ˆκ±°λ‘œμ› λŠ”λ°, 단계λ₯Ό ν•œλ²ˆ 더 μ€„μ΄μ…”μ„œ μ½”λ“œκ°€ κΉ”λ”ν•΄μš” πŸ‘

func addMessage(_ eventType: EventType, _ uid: String, _ userName: String = "") {
        switch eventType {
        case .Change:
            // changeλœλ‹€λŠ” 것 μžμ²΄κ°€ 이미 λ“€μ–΄μ™€μžˆλŠ”λ†ˆ λ°”κΎΈλŠ”κ±°λΌ λ°”λ‘œλ°”λ‘œ μ²˜λ¦¬ν•΄μ€˜λ„λ¨ userDB[uid]κ°€ 없을 ν™•λ₯  μ—†μŒ
            // 문제 μ„€λͺ… δΈ­ - μ±„νŒ…λ°©μ—μ„œ λ‚˜κ°„ μœ μ €κ°€ λ‹‰λ„€μž„μ„ λ³€κ²½ν•˜λŠ” λ“± 잘λͺ» 된 μž…λ ₯은 μ£Όμ–΄μ§€μ§€ μ•ŠλŠ”λ‹€.
            userDB[uid] = userName
        case .Enter:
            userDB[uid] = userName
            enterLogArr.append((event: eventType, uid: uid))
        default:
            enterLogArr.append((event: eventType, uid: uid))
        }
    }
    ```
  μ €λŠ” μ—¬κΈ°μ„œ 또  enterLogArrλ₯Ό μˆœνšŒν•˜λ©΄μ„œ 좜λ ₯을 λ½‘μŠ΅λ‹ˆλ‹·

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finnμŒ€μ€ κ·ΈλŒ€λ‘œ λ‹΄μ•„μ„œ μ°¨λ‘€λ‘œ 좜λ ₯ν–ˆλ„€μš”.

guard let nickname = userDict[userId] else { return nil }

switch action {
case .enter:
return "\(nickname)λ‹˜μ΄ λ“€μ–΄μ™”μŠ΅λ‹ˆλ‹€."
case .leave:
return "\(nickname)λ‹˜μ΄ λ‚˜κ°”μŠ΅λ‹ˆλ‹€."
default:
return nil
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch문도 까먹고 μ „ μ‚Όν•­μ—°μ‚°μž μΌλ„€μš” . .


Comment on lines +12 to +24
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dictionary둜 νŒŒμ‹±ν–ˆκ΅°μš”.

func solution(_ record:[String]) -> [String] {
var res: [String] = []
var userDict: [UserID: Nickname] = [:]
var actions: [(action: Action, id: UserID)] = []

for i in 0..<record.count {
let div = record[i].split(separator: " ").map { String($0) }
let action = Action(rawValue: div[0])!
let userId = div[1]
Comment on lines +30 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recordλ₯Ό μ—¬κΈ°μ„œ λ‹΄κ³  λ‚˜λˆ΄κ΅°μš” !

Comment on lines +31 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

였호 Action을 λ§Œλ“€μ–΄μ„œ enum으둜 ν•˜λ‹ˆ 가독성이 μ’‹λ„€μš”


// λ‹‰λ„€μž„ μ—…λ°μ΄νŠΈ (Enter와 Change)
if action == .enter || action == .change {
userDict[userId] = div[2]
}
Comment on lines +35 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ–΄μ©Œλ©΄ μ œκ°€ λ„ˆλ¬΄ λ³΅μž‘ν•˜κ²Œ ν‘Όκ²ƒμΌμˆ˜ 도 μžˆλ‚˜λ΄μš”.


// λ©”μ‹œμ§€ 생성이 ν•„μš”ν•œ μ•‘μ…˜λ§Œ 기둝 (Enter와 Leave)
if action == .enter || action == .leave {
actions.append((action, userId))
}
}

for action in actions {
if let message = createMessage(action.action, action.id, userDict) {
res.append(message)
}
}
Comment on lines +46 to +50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν•¨μˆ˜ν™” μ‹œμΌœμ£Όλ‹ˆκΉŒ main이 ν™•μ‹€νžˆ κΉ”λ”ν•΄μ§€λ„€μš”


return res
}

Comment on lines +40 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κ·Έλƒ₯ λ¬Έμ œμ—μ„œ μš”κ΅¬ν•˜λŠ”κ²Œ μ—¬λŸ¬ action듀에 λŒ€ν•΄μ„œ ν•˜λ‚˜μ˜ μ•‘μ…˜μ„ κ°€μ Έμ™€μ„œ 배열에 λ‹΄κ³  λ±‰μ–΄μ£ΌκΈ°λ§Œν•˜λ©΄λ˜λŠ”λ°.. μ €λŠ” logκΉŒμ§€ μƒκ°ν•΄μ„œ μ „μ—κ»˜ λ‹€ λ°”λ€Œμ–΄μ•Ό μƒκ°ν•΄μ„œ logν•¨μˆ˜λ₯Ό λ”°λ‘œ μΈ‘μ •ν•˜κ³  generateMessageλ₯Ό ν–ˆμ–΄μš”.

// let record = ["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"]

// let res = solution(record)

// print(res)