프로그래머스 42840. 모의고사

2024. 11. 16. 15:48·프로그래머스

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

def solution(answers):
    first = [1,2,3,4,5]
    second = [2,1,2,3,2,4,2,5]
    third = [3,3,1,1,2,2,4,4,5,5]
    first_cnt, second_cnt, third_cnt = 0,0,0
    for i in range(len(answers)):
        if answers[i] == first[i%5]:
            first_cnt += 1
        if answers[i] == second[i%8]:
            second_cnt += 1
        if answers[i] == third[i%10]:
            third_cnt += 1
    
    answer = []
    max_score = max(first_cnt,second_cnt,third_cnt)
    if first_cnt == max_score:
        answer.append(1)
    if second_cnt == max_score:
        answer.append(2)
    if third_cnt == max_score:
        answer.append(3)
        
    return answer

더 깔끔한 다른사람의 풀이

def solution(answers):
    pattern1 = [1,2,3,4,5]
    pattern2 = [2,1,2,3,2,4,2,5]
    pattern3 = [3,3,1,1,2,2,4,4,5,5]
    score = [0, 0, 0]
    result = []

    for idx, answer in enumerate(answers):
        if answer == pattern1[idx%len(pattern1)]:
            score[0] += 1
        if answer == pattern2[idx%len(pattern2)]:
            score[1] += 1
        if answer == pattern3[idx%len(pattern3)]:
            score[2] += 1

    for idx, s in enumerate(score):
        if s == max(score):
            result.append(idx+1)

    return result
저작자표시 (새창열림)

'프로그래머스' 카테고리의 다른 글

프로그래머스 42839. 소수 찾기  (0) 2024.11.19
프로그래머스 42842. 카펫  (0) 2024.11.17
프로그래머스 77486. 다단계 칫솔 판매  (0) 2024.11.05
프로그래머스 84512. 모음사전  (0) 2024.11.04
프로그래머스 43236. 징검다리  (0) 2024.11.03
'프로그래머스' 카테고리의 다른 글
  • 프로그래머스 42839. 소수 찾기
  • 프로그래머스 42842. 카펫
  • 프로그래머스 77486. 다단계 칫솔 판매
  • 프로그래머스 84512. 모음사전
버그잡는고양이발
버그잡는고양이발
주니어 개발자입니다!
  • 버그잡는고양이발
    지극히평범한개발블로그
    버그잡는고양이발
  • 전체
    오늘
    어제
    • 분류 전체보기 (381)
      • React (16)
      • Next.js (5)
      • Javascript (5)
      • Typescript (4)
      • Node.js (2)
      • Cs (16)
      • 트러블 슈팅 (5)
      • Html (1)
      • Css (3)
      • Django (0)
      • vue (0)
      • Java (1)
      • Python (0)
      • 독서 (1)
      • 기타 (3)
      • 백준 (192)
      • swea (31)
      • 프로그래머스 (30)
      • 이코테 (4)
      • 99클럽 코테 스터디 (30)
      • ssafy (31)
      • IT기사 (1)
  • 블로그 메뉴

    • 홈
    • 태그
  • 인기 글

  • 태그

    개발자취업
    Til
    코딩테스트준비
    항해99
    99클럽
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
버그잡는고양이발
프로그래머스 42840. 모의고사
상단으로

티스토리툴바