-
Notifications
You must be signed in to change notification settings - Fork 0
4-MuchanKim #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4-MuchanKim #20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import Foundation | ||
|
|
||
| typealias UserID = String | ||
| typealias Nickname = String | ||
|
|
||
| enum Action: String { | ||
| case enter = "Enter" | ||
| case leave = "Leave" | ||
| case change = "Change" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ μ λ μ¬κΈ°μ μ΄κ±°ν μΈ μκ° λͺ» νκ³ ifλ¬ΈμΌλ‘ μΌλλ° λ³΄κΈ° μ’μμ ππ»
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μλ γ γ γ κ± κ°κ° λͺ λ Ήμ΄ recordλλκ³ λ΄κ³ μνκΉμ§μνκ³ κ± λ€μ΄μ€λ©΄ λ€μ΄μ€λλ°λ‘ λκ°λ©΄ λκ°λλ°λ‘ μ°μ΄μ£Όλ κ±°μλ€μ γ γ γ ν.... κΈλ‘λ μ½λλ μ λ³΄κ³ κ°λλ€.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν enumμ μ΄λ κ²μ¨μ νλκ² μμλ€μ ifλ¬ΈμΌλ‘ λμΆ© νλλ° μ’κ΅°μ! |
||
| } | ||
|
|
||
| func createMessage(_ action: Action, _ userId: UserID, _ userDict: [UserID: Nickname]) -> String? { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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λ₯Ό μννλ©΄μ μΆλ ₯μ λ½μ΅λλ·
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switchλ¬Έλ κΉλ¨Ήκ³ μ μΌνμ°μ°μ μΌλ€μ . . |
||
|
|
||
|
Comment on lines
+12
to
+24
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recordλ₯Ό μ¬κΈ°μ λ΄κ³ λλ΄κ΅°μ !
Comment on lines
+31
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν¨μν μμΌμ£ΌλκΉ mainμ΄ νμ€ν κΉλν΄μ§λ€μ |
||
|
|
||
| return res | ||
| } | ||
|
|
||
|
Comment on lines
+40
to
+54
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typealias λ₯Ό μ¬μ©νμ ¨κ΅°μ !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μΉ typealiasλ μκ°μνκ³ κ΅¬ννλλ° μ΄κ²λ μ’λ€μ!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typealias fxxking Swiftful!