알고리즘/프로그래머스 문제풀이

[프로그래머스] lv.1 모의고사 python 풀이

감자156 2023. 10. 24. 14:01
반응형

문제

https://school.programmers.co.kr/learn/courses/30/lessons/42840

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

문제 풀이

단순 구현 완전탐색.

 

코드

def solution(answers):
    p1 = [1,2,3,4,5,1,2,3,4,5]
    p2 = [2,1,2,3,2,4,2,5]
    p3 = [3,3,1,1,2,2,4,4,5,5]
    res = [0, 0, 0]
    for i in range(len(answers)):
        if answers[i] == p1[i%10] : res[0] += 1
        if answers[i] == p2[i%8] : res[1] += 1
        if answers[i] == p3[i%10] : res[2] += 1
    
    tmp = []
    for i in range(len(res)):
        if res[i] == max(res):
            tmp.append(i+1)
    return tmp
반응형