[프로그래머스] 모의고사 Python
·
개발💻/알고리즘
아직 레벨1 문제들을 풀면서 감각을 살리는 중이다 def solution(answers): answer = [] rate = [-1] + [0]*3 omr_1 = [1,2,3,4,5]*((len(answers) //5) +1) omr_2 = [2,1,2,3,2,4,2,5]*((len(answers) //8) +1) omr_3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]*((len(answers) // 10) +1) for i in range(len(answers)): if answers[i] == omr_1[i]: rate[1] +=1 if answers[i] == omr_2[i]: rate[2] +=1 if answers[i] == omr_3[i]: rate[3] +=1 max_value..
[프로그래머스] 체육복 Python
·
개발💻/알고리즘
잘 푼거같은데 자꾸 테스트 통과를 못해서 엄청 찾다가 인덱스가 문제라는걸 알았다 항상 range 든 list 든 탐색할때 0 부터 시작한다는걸 잊지말자!! def solution(n, lost, reserve): cloth = [1]*(n+1) for i in range(1,n+1): if i in lost and i in reserve: cloth[i] = 1 continue if i in lost: cloth[i] = 0 if i in reserve: cloth[i] = 2 print(cloth) answer = 0 for i in range(1, n+1): if cloth[i] == 0: if i > 1: if cloth[i - 1] == 2: cloth[i] +=1 cloth[i - 1] -=1 ..
[프로그래머스] 실패율 Python
·
개발💻/알고리즘
진짜 처음부터 하나하나 하려다보니 넘 어렵다.. 기초부터 다 찾아봐야하고 ㅠㅠ def solution(N, stages): rate = [0]*(N+1) man = len(stages) stage = 1 while stage 0: count = 0 for st in stages: if st == stage: count +=1 rate[stage-1] = count / man man -= count stage += 1 rate = rate[:-1] answer = [] while len(rate) != len(answer): max_value = max(rate) print(max_value) for i in range(len(rate)): if rate[i] == max_va..