Created
July 4, 2019 14:21
-
-
Save cg4jins/d93a62d050dcdef9a4f97cfa7e373af5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
fun solution(record: Array<String>): Array<String> { | |
var answer = mutableListOf<String>() | |
var nickNameMap = mutableMapOf<String, String>() | |
var history = mutableListOf<Pair<String, String>>() | |
for (line in record) { | |
val tokens = line.split(" ") | |
when { | |
tokens[0] == "Enter" -> { | |
nickNameMap[tokens[1]] = tokens[2] | |
history.add(Pair(tokens[0], tokens[1])) | |
} | |
tokens[0] == "Change" -> nickNameMap[tokens[1]] = tokens[2] | |
else -> history.add(Pair(tokens[0], tokens[1])) | |
} | |
} | |
for (hist in history) { | |
val command = when (hist.first) { | |
"Enter" -> "님이 들어왔습니다." | |
"Leave" -> "님이 나갔습니다." | |
else -> "" | |
} | |
answer.add("${nickNameMap[hist.second]}$command") | |
} | |
return answer.toTypedArray() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment