누가 봐도 mbti 에서 영감받은 문제였던 것임 ,,
from collections import defaultdict
alpha = [['R', 'T'], ['C', 'F'], ['J', 'M'], ['A', 'N']]
li = defaultdict(int)
def solution(survey, choices):
answer = ''
for i in range(len(survey)) :
if choices[i] < 4 :
li[survey[i][0]] += 1
elif choices[i] > 4 :
li[survey[i][1]] += 1
for al in alpha :
answer += comp(al[0], al[1])
return answer
def comp(f, s):
if li[f] > li[s] :
return f
elif li[f] < li[s] :
return s
else :
return sorted([f, s])[0]
ㅎㅎ 레벨 1이라고 정신 안 차렸나봄
+3, +2, +1 이렇게 점수 차이 있는 걸 생각 안 함
from collections import defaultdict
alpha = [['R', 'T'], ['C', 'F'], ['J', 'M'], ['A', 'N']]
li = defaultdict(int)
def solution(survey, choices):
answer = ''
for i in range(len(survey)) :
if choices[i] < 4 :
li[survey[i][0]] += (4-choices[i])
elif choices[i] > 4 :
li[survey[i][1]] += (choices[i]-4)
for al in alpha :
answer += comp(al[0], al[1])
return answer
def comp(f, s):
if li[f] == li[s] :
return f
elif li[f] < li[s] :
return s
else :
return sorted([f, s])[0]
그냥 defaultdict 로 다 초기화해놓고 점수 비교한 게 다인 듯
암튼 앞으로 문제 꼬박꼬박 풀겠읍니다
'알고리즘' 카테고리의 다른 글
[프로그래머스 Lv2 - 2022 KAKAO BLIND RECRUITMENT] k진수에서 소수 개수 구하기 (Python) (0) | 2022.09.16 |
---|---|
[프로그래머스 Lv2 - 2022 KAKAO BLIND RECRUITMENT] 주차 요금 계산 (Python) (0) | 2022.09.16 |
[프로그래머스 Lv3] - 숫자 게임 (Python) (1) | 2022.08.06 |
[프로그래머스 Lv2] 괄호 회전하기 (Python) (0) | 2022.08.04 |
[프로그래머스 Lv3] 베스트앨범 (Python) (0) | 2022.07.28 |