プログラマー-模擬試験


未熟な問題解は正解にはならず,もちろんこれよりも有効なコードがある.
参考までに、いつでもご返事をお待ちしております.🤍
def solution(answers):
    qnum=int(len(answers)/5)+1
    score={1:0,2:0,3:0}
    supo1 = [1,2,3,4,5]*qnum
    supo2 = [2, 1, 2, 3, 2, 4, 2, 5]*qnum
    supo3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]*qnum

    for i in range (0,len(answers)):
        if answers[i]==supo1[i]:
            score[1]=score[1]+1
        if answers[i]==supo2[i]:
            score[2]=score[2]+1
        if answers[i]==supo3[i]:
            score[3]=score[3]+1


    answer = sorted([k for k,v in score.items() if max(score.values()) == v])


    return answer