728x90
처음으로 카카오 문제를 완벽하게 맞았다. 코드가 지저분 하긴 하지만 맞아서 다행이다. 문제 파악이 가장 중요한 것 같다.
def solution(survey, choices):
answer = ""
# R T C F J M A N 1 2 3 4 5 6 7 8
k = [0,0,0,0,0,0,0,0]
for i in range(0,len(choices)):
if choices[i]==4:
continue
else:
if choices[i]<=3:
if survey[i][0]=="R":
k[0]+=(4-choices[i])
if survey[i][0]=="T":
k[1]+=(4-choices[i])
if survey[i][0]=="C":
k[2]+=(4-choices[i])
if survey[i][0]=="F":
k[3]+=(4-choices[i])
if survey[i][0]=="J":
k[4]+=(4-choices[i])
if survey[i][0]=="M":
k[5]+=(4-choices[i])
if survey[i][0]=="A":
k[6]+=(4-choices[i])
if survey[i][0]=="N":
k[7]+=(4-choices[i])
else:
if survey[i][1]=="R":
k[0]+=(choices[i]-4)
if survey[i][1]=="T":
k[1]+=(choices[i]-4)
if survey[i][1]=="C":
k[2]+=(choices[i]-4)
if survey[i][1]=="F":
k[3]+=(choices[i]-4)
if survey[i][1]=="J":
k[4]+=(choices[i]-4)
if survey[i][1]=="M":
k[5]+=(choices[i]-4)
if survey[i][1]=="A":
k[6]+=(choices[i]-4)
if survey[i][1]=="N":
k[7]+=(choices[i]-4)
if k[0]>=k[1]:
answer += "R"
else:
answer+="T"
if k[2]>=k[3]:
answer += "C"
else:
answer+="F"
if k[4]>=k[5]:
answer += "J"
else:
answer+="M"
if k[6]>=k[7]:
answer += "A"
else:
answer+="N"
return answer728x90
'🟢 알고리즘 문제 풀이 > Programmers' 카테고리의 다른 글
| [파이썬] 프로그래머스 귤 고르기 (0) | 2023.01.02 |
|---|---|
| [파이썬] 프로그래머스 최댓값과 최솟값 (0) | 2023.01.02 |
| [파이썬] 프로그래머스 크기가 작은 부분 문자열 (0) | 2023.01.01 |
| [파이썬] 프로그래머스 가장 가까운 같은 글자 (0) | 2023.01.01 |
| [파이썬] 프로그래머스 푸드 파이트 대회 (0) | 2023.01.01 |