728x90
문제 설명
문제 풀이 과정
포인트는 앞에 있는 동점일 경우 앞의 유형 글자를 추가하는 것
def solution(survey, choices):
sur = {'R': 0, 'T': 0, 'C': 0, 'F': 0, 'J': 0, 'M':0, 'A': 0, 'N':0}
score = [3,2,1,0,1,2,3]
answer = ''
for tp, sc in zip(survey, choices):
if sc < 4:
sur[tp[:1]] += score[sc-1]
elif sc > 4:
sur[tp[1:]] += score[sc-1]
if sur['R'] >= sur['T']:
answer += 'R'
else:
answer += 'T'
if sur['C'] >= sur['F']:
answer += 'C'
else:
answer += 'F'
if sur['J'] >= sur['M']:
answer += 'J'
else:
answer += 'M'
if sur['A'] >= sur['N']:
answer += 'A'
else:
answer += 'N'
return answer
다른 사람의 풀이
def solution(survey, choices):
my_dict = {"RT":0,"CF":0,"JM":0,"AN":0}
for A,B in zip(survey,choices):
if A not in my_dict.keys():
A = A[::-1]
my_dict[A] -= B-4
else:
my_dict[A] += B-4
result = ""
for name in my_dict.keys():
if my_dict[name] > 0:
result += name[1]
elif my_dict[name] < 0:
result += name[0]
else:
result += sorted(name)[0]
return result
구현은 어렵지 않았다.
- coding test url:
https://school.programmers.co.kr/learn/courses/30/lessons/118666
728x90
'Coding test' 카테고리의 다른 글
[2021 Dev-Matching] 로또의 최고 순위와 최저 순위 (0) | 2022.12.19 |
---|---|
[KAKAO BLIND RECRUITMENT] 신고 결과 받기(python) (0) | 2022.12.16 |
[Programmers] 숫자 짝꿍 (0) | 2022.12.12 |
[Programmers] 삼총사 (0) | 2022.12.12 |
[Programmers] 콜라 문제 (0) | 2022.12.12 |