문제
알고리즘
- 성격 유형을 비교한 후 점수를 부여한다.
- 비교를 모두 한 후 성격 유형의 점수와 이름순에 따라 성격 유형을 완성한다.
코드
def solution(survey, choices):
answer = ''
dic = {"R": 0, "T": 0, "C": 0, "F": 0, "J": 0, "M": 0, "A": 0, "N": 0}
n = len(survey)
for i in range(n):
x, y = survey[i].strip()
if choices[i] < 4:
dic[x] += 4 - choices[i]
elif choices[i] > 4:
dic[y] += choices[i] - 4
if dic["R"] < dic["T"]:
answer += "T"
else:
answer += "R"
if dic["C"] < dic["F"]:
answer += "F"
else:
answer += "C"
if dic["J"] < dic["M"]:
answer += "M"
else:
answer += "J"
if dic["A"] < dic["N"]:
answer += "N"
else:
answer += "A"
return answer
github
'CodingTest > Programers' 카테고리의 다른 글
[programers] 프로그래머스(코틀린) : 없는 숫자 더하기 (0) | 2022.09.07 |
---|---|
[programers] 프로그래머스(파이썬) : 없는 숫자 더하기 (0) | 2022.09.07 |
[programers] 프로그래머스(파이썬) : 가장 큰 수 (1) | 2022.08.31 |
[programers] 프로그래머스(코틀린) : 크레인 인형뽑기 게임 (0) | 2022.08.29 |
[programers] 프로그래머스(파이썬) : 크레인 인형뽑기 게임 (0) | 2022.08.29 |