문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/118666
1) 풀이
문제가 너무 길어서 문제 읽는데만 대부분 시간을 소요한 문제였다.
간단한 구현문제.
먼저 내가 푼 방식은 이렇다.
각 성격 유형별 point를 저장하는 dictionary를 선언해준후 survey 결과를 반복문을 통해 차례대로 보면서 만약 choices의 인덱스가 비동의를 넘어가는 순간 반대 성격 타입에 점수를 +해주는 식으로 구현을 했다.
def solution(survey, choices):
point = [3, 2, 1, 0, 1, 2, 3]
type_point = {'R': 0, 'T': 0, 'C': 0, 'F': 0, 'J': 0, 'M': 0, 'A': 0, 'N': 0}
for i in range(len(survey)):
type_1, type_2 = survey[i][0], survey[i][1]
if choices[i] - 1 == 3:
continue
if choices[i] - 1 < 3:
type_point[type_1] += point[choices[i] - 1]
else:
type_point[type_2] += point[choices[i] - 1]
answer = ''
if type_point['R'] >= type_point['T']:
answer += 'R'
else:
answer += 'T'
if type_point['C'] >= type_point['F']:
answer += 'C'
else:
answer += 'F'
if type_point['J'] >= type_point['M']:
answer += 'J'
else:
answer += 'M'
if type_point['A'] >= type_point['N']:
answer += 'A'
else:
answer += 'N'
return answer
'Algorithm' 카테고리의 다른 글
[프로그래머스- lv2] 미로 탈출/ 파이썬 (0) | 2023.02.20 |
---|---|
[BOJ -1256 사전찾기 / 파이썬] (2) | 2023.02.16 |
[프로그래머스 - lv1] 2016년 (0) | 2023.02.06 |
[프로그래머스 - lv0] 주사위의 개수 (0) | 2023.02.05 |
[프로그래머스-lv0]문자열 정렬하기(1) (0) | 2023.02.05 |