반응형
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 |
31 |
Tags
- 금고털이 파이썬
- 백준 전쟁-전투
- 도커 컨테이너
- MySQL완전삭제
- 소프티어 지도자동구축
- CRUD
- 백준 점프
- 백준 피아노체조
- express mongodb
- 1987파이썬
- 백준
- 등수매기기 파이썬
- 백준알파벳파이썬
- 파이썬데이터분석라이브러리
- express
- 백준 전쟁 파이썬
- 백준 평범한배낭
- 지도자동구축 파이썬
- 피아노체조 파이썬
- 프로그래머스
- 백준 점프 파이썬
- 소프티어 장애물인식프로그램
- 백준 등수매기기
- 백준 A->B
- 장애물인식프로그램 파이썬
- MongoDB
- 파이썬 평범한배낭
- jenkins
- 백준 바이러스
- 백준 예산
Archives
- Today
- Total
바위 뚫는중
[프로그래머스] Lv1. 모의고사 - 완전탐색 본문
반응형
1️⃣ 모의고사
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42840?language=python3
💡 아이디어
말그대로 완전탐색을 해준다!
인덱스 순서에 유의하며 문제를 풀었다.
📝 풀이
나머지를 활용해서 인덱스를 구하였고, dict를 사용하여 append 해주었다.
다소 비효율적이고 매우 풀어썼음
def solution(answers):
answer = []
a = [1, 2, 3, 4, 5]
b = [2, 1, 2, 3, 2, 4, 2, 5]
c = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
aa = 0
bb = 0
cc = 0
for i in range(len(answers)):
if a[(i + 1) % len(a) - 1] == answers[i]:
aa += 1
if b[(i + 1) % len(b) - 1] == answers[i]:
bb += 1
if c[(i + 1) % len(c) - 1] == answers[i]:
cc += 1
dict = {'1' : aa, '2': bb, '3':cc}
max = 0
for items in dict:
if dict[items] >= max:
if dict != 0:
max = dict[items]
for items in dict:
if dict[items] == max:
if items == '1':
answer.append(1)
if items == '2':
answer.append(2)
if items == '3':
answer.append(3)
return answer
구글링 하다 찾은 다른 사람들 간단한 풀이
def solution(answers):
supojas = [[1,2,3,4,5],[2,1,2,3,2,4,2,5], [3,3,1,1,2,2,4,4,5,5]]
res = []
for person in supojas:
k, count = 0, 0
length = len(person)
for ans in answers:
if ans == person[k]:
count+=1
k+=1
k%=length
res.append(count)
maxvalue = max(res)
answer= []
for i in range(3):
if res[i] == maxvalue:
answer.append(i+1)
return answer
👩🏻💻 느낀점
이중배열을 쓰면 코드가 훨씬 간단해진다
반응형
'Algorithms > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Lv3. 단어 변환 (0) | 2023.11.08 |
---|---|
[프로그래머스] Lv1. 기능개발 - 스택,큐 (0) | 2023.10.27 |
[프로그래머스] Lv1. 성격 유형 검사하기 - 문자열 (0) | 2023.10.26 |
[프로그래머스] Lv 1. 추억 점수, Lv1. 대충 만든 자판 - 문자열 딕셔너리, enumerate (0) | 2023.10.26 |
[프로그래머스] Lv0. 한 번만 등장한 문자, Lv0. 최빈값 구하기 - 문자열 Counter, Defaultdict (0) | 2023.10.26 |