Notice
Recent Posts
Link
- Today
- Total
hye-log
[프로그래머스]성격 유형 검사하기(Python) 본문
0. 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/118666?language=python3
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 문제 소개
1) 문제 유형 별 점수 더하기
2) 문제 유형 둘 중 더 큰 값인 유형 찾기
2. 입출력
# input
survey = ["AN", "CF", "MJ", "RT", "NA"]
choices = [5, 3, 2, 7, 5]
# output
result = "TCMA"
3. 코드
def solution(survey, choices):
answer = []
k_character = {'R':0, 'T':0, 'C':0, 'F':0, 'J':0, 'M':0, 'A':0, 'N':0}
for i in range(len(survey)):
if choices[i] < 4: # 값이 4보다 작으면
k_character[survey[i][0]] += 4 - choices[i] # 첫 번째 유형에 점수 더하기
if choices[i] > 4: # 값이 4보다 크면
k_character[survey[i][1]] += choices[i] - 4 # 두 번째 유형에 점수 더하기
if k_character['R'] < k_character['T']:
answer.append('T')
else:
answer.append('R')
if k_character['C'] < k_character['F']:
answer.append('F')
else:
answer.append('C')
if k_character['J'] < k_character['M']:
answer.append('M')
else:
answer.append('J')
if k_character['A'] < k_character['N']:
answer.append('N')
else:
answer.append('A')
return ''.join(answer)
실행 결과
5. Github
https://github.com/iihye/Algorithm/blob/main/Programmers/personality_test.py
GitHub - iihye/Algorithm
Contribute to iihye/Algorithm development by creating an account on GitHub.
github.com
728x90
'CodingTest > Programmers' 카테고리의 다른 글
[프로그래머스]JadenCase 문자열 만들기(Python) (0) | 2022.09.15 |
---|---|
[프로그래머스]최댓값과 최솟값(Python) (0) | 2022.09.14 |
[프로그래머스]124 나라의 숫자(Python) (0) | 2022.08.26 |
[프로그래머스]H-Index(Python) (0) | 2022.08.23 |
[프로그래머스]멀쩡한 사각형(Python) (0) | 2022.08.19 |
Comments