# 문제: https://school.programmers.co.kr/learn/courses/30/lessons/118666
# 유형 산출 부분을 어떻게 하면 더 효율적으로 만들 수 있을까?
def solution(survey, choices):
answer = []
dic = {'R':0, 'T':0,'C':0,'F':0,'J':0,'M':0,'A':0,'N':0}
# 유형 검사
for survey_type, choices_num in zip(survey, choices):
# print(survey_type, choices_num)
if choices_num < 4:
dic[survey_type[0]] += (4 - choices_num)
elif choices_num == 4:
pass
elif choices_num > 4:
dic[survey_type[1]] += (choices_num - 4)
#유형 산출
if dic['R'] > dic['T']:
answer.append('R')
elif dic['R'] == dic['T']:
answer.append('R')
else:
answer.append('T')
if dic['C'] > dic['F']:
answer.append('C')
elif dic['C'] == dic['F']:
answer.append('C')
else:
answer.append('F')
if dic['J'] > dic['M']:
answer.append('J')
elif dic['J'] == dic['M']:
answer.append('J')
else:
answer.append('M')
if dic['A'] > dic['N']:
answer.append('A')
elif dic['A'] == dic['N']:
answer.append('A')
else:
answer.append('N')
return "".join(answer)
반응형
'공부 서랍장 > 알고리즘 공부' 카테고리의 다른 글
[프로그래머스] 모음사전 python (0) | 2022.09.18 |
---|---|
[프로그래머스] H-Index python (0) | 2022.09.18 |
[프로그래머스] 신고 결과 받기 python (0) | 2022.09.18 |
[프로그래머스] 이상한 문자 만들기 python (0) | 2022.09.17 |
[프로그래머스] 최소직사각형 python (0) | 2022.09.17 |