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 answer
728x90

+ Recent posts