CodingTest/Programers

[programers] 프로그래머스(파이썬) : 성격 유형 검사하기

JunJangE 2022. 9. 4. 14:48

문제

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

알고리즘

- 성격 유형을 비교한 후 점수를 부여한다.

- 비교를 모두 한 후 성격 유형의 점수와 이름순에 따라 성격 유형을 완성한다.

코드

def solution(survey, choices):
    answer = ''
    dic = {"R": 0, "T": 0, "C": 0, "F": 0, "J": 0, "M": 0, "A": 0, "N": 0}
    n = len(survey)

    for i in range(n):
        x, y = survey[i].strip()
        if choices[i] < 4:
            dic[x] += 4 - choices[i]
        elif choices[i] > 4:
            dic[y] += choices[i] - 4

    if dic["R"] < dic["T"]:
        answer += "T"
    else:
        answer += "R"

    if dic["C"] < dic["F"]:
        answer += "F"
    else:
        answer += "C"

    if dic["J"] < dic["M"]:
        answer += "M"
    else:
        answer += "J"

    if dic["A"] < dic["N"]:
        answer += "N"
    else:
        answer += "A"

    return answer

github