Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- DP
- oracle
- 다익스트라
- DFS
- 그래프 이론
- 다이나믹 프로그래밍
- 너비우선탐색
- 오라클
- 프로그래머스
- 브루트포스
- 완전탐색
- 백트래킹
- 데이터베이스
- 구현
- 그래프 탐색
- 파이썬
- BFS
- 브루트포스 알고리즘
- javascript
- 너비 우선 탐색
- Python
- SW Expert Academy
- 백준 알고리즘
- 백준알고리즘
- 깊이우선탐색
- 문자열
- 자바스크립트
- 그리디 알고리즘
- SWEA
- 스택
Archives
- Today
- Total
민규의 흔적
[Python 파이썬] 프로그래머스 - 모의고사 본문
2024년 7월 8일
문제 링크 : 프로그래머스 - 모의고사
문제 접근
문제가 요구하는 사항들이 명확해, 문제가 요구하는 사항들을 잘 읽기만 한다면 간단히 풀 수 있는 문제라고 생각한다.
수포자는 총 3명이다.
1번 수포자는 1, 2, 3, 4, 5를 반복하며 찍는다.
2번 수포자는 2, 1, 2, 3, 2, 4, 2, 5를 반복하며 찍는다.
3번 수포자는 3, 3, 1, 1, 2, 2, 4, 4, 5, 5를 반복하며 찍는다.
가장 많이 맞은 사람을 배열에 출력하면 되며, 가장 많이 맞은 사람이 여럿 존재할 경우 오름차순으로 배열에 담아 출력한다.
전체 코드
def solution(answers):
answer = []
first_idx = 0
first_cnt = 0
first = [1, 2, 3, 4 ,5]
first_len = 5
second_idx = 0
second_cnt = 0
second = [2, 1, 2, 3, 2, 4, 2, 5]
second_len = 8
third_idx = 0
third_cnt = 0
third = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
third_len = 10
answers_idx = 0
while (answers_idx < len(answers)):
if answers[answers_idx] == first[first_idx]:
first_cnt += 1
if answers[answers_idx] == second[second_idx]:
second_cnt += 1
if answers[answers_idx] == third[third_idx]:
third_cnt += 1
answers_idx += 1
first_idx = (first_idx + 1) % first_len
second_idx = (second_idx + 1) % second_len
third_idx = (third_idx + 1) % third_len
max_cnt = max(first_cnt, second_cnt, third_cnt)
if first_cnt == max_cnt:
answer.append(1)
if second_cnt == max_cnt:
answer.append(2)
if third_cnt == max_cnt:
answer.append(3)
return answer
if __name__ == "__main__":
answers = [1,2,3,4,5]
print(solution(answers))
풀이 후기
문제가 요구하는 사항만 따라서 코드를 작성하면 되는 문제였다.
'프로그래머스' 카테고리의 다른 글
[Python 파이썬] 프로그래머스 - 다리를 지나는 트럭 (0) | 2024.07.17 |
---|---|
[Python 파이썬] 프로그래머스 - 이중우선순위큐 (1) | 2024.07.15 |
[Python 파이썬] 프로그래머스 - 게임 맵 최단거리 (3) | 2024.07.05 |
[Python 파이썬] 프로그래머스 - 전력망을 둘로 나누기 (0) | 2024.07.05 |
[JavaScript 자바스크립트] 프로그래머스 - 카펫 (0) | 2024.06.30 |