문제 :
코딩테스트 연습 - 모의고사
수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는
programmers.co.kr
Solution
def solution(answers):
answer = []
s1=[1,2,3,4,5]
s2=[2,1,2,3,2,4,2,5]
s3=[3,3,1,1,2,2,4,4,5,5]
c1=c2=c3=0 #맞은 문제 수
p1=p2=p3=0 #위치
for i in range(len(answers)):
if answers[i]==s1[p1]:c1+=1
if answers[i]==s2[p2]:c2+=1
if answers[i]==s3[p3]:c3+=1
p1+=1
p2+=1
p3+=1
if p1==len(s1):p1=0
if p2==len(s2):p2=0
if p3==len(s3):p3=0
maxscore=max(c1,c2,c3)
if c1==maxscore:answer.append(1)
if c2==maxscore:answer.append(2)
if c3==maxscore:answer.append(3)
return answer
반응형
'Problem Solving > Programmers' 카테고리의 다른 글
SQL (Level 3) 헤비 유저가 소유한 장소 : 2021 Dev-Matching 웹 백엔드 개발자(상반기) - Group by, Having, inner join (0) | 2021.07.09 |
---|---|
그리디 (Level 1) : 체육복 (Python, copy 라이브러리) (0) | 2021.05.17 |
정렬 (Level 1) : k번째 수 (Python) (0) | 2021.05.10 |
스택/큐 (Level 2) : 주식가격 (Python) (0) | 2021.05.09 |
DFS/BFS (Level 2) : 타겟 넘버 (Python) (0) | 2021.05.08 |