[ProblemSolving] 프로그래머스 위클리챌린지 - 2주차 상호평가

문제 링크

입출력 예

scores												result
[[100,90,98,88,65],[50,45,99,85,77],[47,88,95,80,67],[61,57,100,80,65],[24,90,94,75,65]]	"FBABD"
[[50,90],[50,87]]										"DA"
[[70,49,90],[68,50,38],[73,31,100]]								"CFD"

나의 풀이

쉽습니다..

코드

def grade(sum_):
    ans =''
    if 90<= sum_:
        ans += 'A' 
    elif 80 <= sum_ < 90:
        ans += 'B'
    elif 70 <= sum_ < 80:
        ans += 'C'
    elif 50 <= sum_ < 70:
        ans += 'D' 
    else:
        ans+= 'F'
    return ans

def solution(scores):
    answer = ''
    average = []
    n= len(scores)
    for j in range(n):
        sum_ = 0
        for i in range(n):
            average.append(scores[i][j])     
        if (average[j] == max(average) or  average[j] == min(average)) and average.count(average[j])==1:
            del(average[j])
        answer += grade(sum(average)/len(average))
        average = []
            
    return answer

다른 분 코드

ef solution(scores) :
    avgs=[]
    score=[ [i[j] for i in scores] for j in range(len(scores))]
    for idx,i in enumerate(score) :
        avg=sum(i) ; length=len(i)
        if i[idx] == max(i) or i[idx] == min(i) :
            if i.count(i[idx]) == 1 :
                avg-=i[idx] ; length-=1
        avgs.append(avg/length)
    return "".join([ avg>=90 and "A" or avg>=80 and "B" or avg>=70 and "C" or avg>=50 and "D" or "F" for avg in avgs ])

좋은 웹페이지 즐겨찾기