반응형
감을 살리기 위해 기본문제부터 시작하겠다
반복문 조건문도 까먹어서 검색하면서 풀었다..
def solution(survey, choices):
answer = ''
result_table = {'R' : 0, 'T': 0, 'C':0,'F':0,'J':0,'M':0,'A':0,'N':0 }
Length = len(survey)
index = 0
while index < Length:
if choices[index] > 4:
result_table[survey[index][1]] += choices[index] - 4
elif choices[index] < 4:
result_table[survey[index][0]] += 4 - choices[index]
else:
pass
index +=1
if result_table['R'] >= result_table['T']:
answer += 'R'
else:
answer += 'T'
if result_table['C'] >= result_table['F']:
answer += 'C'
else:
answer += 'F'
if result_table['J'] >= result_table['M']:
answer += 'J'
else:
answer += 'M'
if result_table['A'] >= result_table['N']:
answer += 'A'
else:
answer += 'N'
return answer
쫌 노가다를 해서 푼 느낌이 있긴하지만 나름 깔끔하게 잘 풀었다고 생각한다
딕셔너리에 각각의 점수를 저장하고 그 점수중 2개씩 유형을 비교해서 정답을 출력했다
그리고 점수가 동점일때는 알파뱃순으로 결과를 넣어줘야하는데 >= 로 해결했다
조금씩이라도 꾸준히 풀어서 올리겠다!!
반응형
'개발💻 > 알고리즘' 카테고리의 다른 글
[프로그래머스] 타겟 넘버 Python (0) | 2024.03.11 |
---|---|
[프로그래머스] 모의고사 Python (25) | 2024.03.09 |
[프로그래머스] 체육복 Python (25) | 2024.03.08 |
[프로그래머스] 실패율 Python (0) | 2024.03.08 |
알고리즘 다시 시작... (2) | 2024.03.06 |