Skip to content
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

프로그래머스_Lv1_성격유형검사하기_이승범 #27

Merged
merged 1 commit into from
Dec 3, 2024
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
Binary file modified seungbum/.DS_Store
Binary file not shown.
47 changes: 47 additions & 0 deletions seungbum/week5/프로그래머스_Lv1_성격유형검사하기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package koala.programmers

fun solution(survey: Array<String>, choices: IntArray): String {
val personalType = mutableMapOf(
"R" to 0, "T" to 0,
"C" to 0, "F" to 0,
"J" to 0, "M" to 0,
"A" to 0, "N" to 0
)

for (i in choices.indices) {
val choice = choices[i]
when {
(choice == 4) ->
continue

(choice < 4) ->
personalType[survey[i][0].toString()] = personalType[survey[i][0].toString()]!! + (4 - choice)

else ->
personalType[survey[i][1].toString()] = personalType[survey[i][1].toString()]!! + choice - 4
}
}
val answer = buildString {
append(if (personalType["R"]!! < personalType["T"]!!) "T" else "R")
append(if (personalType["C"]!! < personalType["F"]!!) "F" else "C")
append(if (personalType["J"]!! < personalType["M"]!!) "M" else "J")
append(if (personalType["A"]!! < personalType["N"]!!) "N" else "A")
}
return answer
}

fun main() {
// Array<String> for survey choices
val surveyChoices: Array<String> = arrayOf("AN", "CF", "MJ", "RT", "NA")
val surveyChoices2: Array<String> = arrayOf("TR", "RT", "TR")


// IntArray for results
val surveyResults: IntArray = intArrayOf(5, 3, 2, 7, 5)
val surveyResults2: IntArray = intArrayOf(7, 1, 3)


val result = solution(surveyChoices, surveyResults)

print(solution(surveyChoices2,surveyResults2))
}