diff --git "a/Hongjoo/lv2/3\354\260\250_\354\225\225\354\266\225.py" "b/Hongjoo/lv2/3\354\260\250_\354\225\225\354\266\225.py" new file mode 100644 index 0000000..3fae74b --- /dev/null +++ "b/Hongjoo/lv2/3\354\260\250_\354\225\225\354\266\225.py" @@ -0,0 +1,34 @@ +""" +## 프로그래머스#17684. [3차]_압축: 구현 / lv2 +> 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/17684 +""" +def solution(msg): + answer = [] + # 1. 사전 초기기 + dict = {} + idx = 1 # 초기 사전 idx + for o in range(65, 65+ 26) : + dict[chr(o)] = idx + idx += 1 + last_idx = idx-1 + #2. 입출력 단어 압축하기 + prev_idx = -1 + w_s = 0 ; w_l = 1 + while w_s+w_l <= len(msg) : + word = msg[w_s : w_s + w_l] + idx = dict.get(word , -1 ) + if idx > -1 : + prev_idx = idx + w_l += 1 + continue + #사전에 없음 + else : + last_idx += 1 + dict[word] = last_idx # 사전 등록하기 + w_s = w_s + w_l - 1 #탐색 point 업데이트 + w_l = 1 # 단어 길이 초기화 + answer+= [prev_idx]# 이전 존재한 단어의 idx 는 출력 리스트에 추가 + answer+= [prev_idx] # 마지막 w 의 인덱스 출력 + + + return answer \ No newline at end of file diff --git "a/Hongjoo/lv2/\352\270\260\353\212\245\352\260\234\353\260\234.py" "b/Hongjoo/lv2/\352\270\260\353\212\245\352\260\234\353\260\234.py" new file mode 100644 index 0000000..2112a82 --- /dev/null +++ "b/Hongjoo/lv2/\352\270\260\353\212\245\352\260\234\353\260\234.py" @@ -0,0 +1,27 @@ +""" +## 프로그래머스#42586. 기능개발 : 구현, 큐/lv2 +> 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42586 + +""" +import math +from collections import deque +def solution(progresses, speeds): + answer = [] + # 1. progress별로 추가 Day 구하기 + days= deque([0 for _ in range(len(progresses))]) + for i in range(len(progresses)) : + days[i] = math.ceil((100 - progresses[i]) / speeds[i]) + # print(days) + #2. 같은 배포일을 가진 서비스 개수들 구하기 + while days : + tmp = 0 + develop_day = days[0] + # deque로 develop_days보다 더 빠르게 종료되는 서비스들은 pop + while days and develop_day >= days[0] : + tmp += 1 + days.popleft() + # 해당 develop_day보다 큰 경우, 그 전까지 서비스들이 같은 배포일 가짐 + answer.append(tmp) + + + return answer \ No newline at end of file diff --git "a/Hongjoo/lv2/\354\212\244\355\202\254\355\212\270\353\246\254.py" "b/Hongjoo/lv2/\354\212\244\355\202\254\355\212\270\353\246\254.py" new file mode 100644 index 0000000..4f8b556 --- /dev/null +++ "b/Hongjoo/lv2/\354\212\244\355\202\254\355\212\270\353\246\254.py" @@ -0,0 +1,25 @@ + +# skillset이 선행조건 충족 여부 확인 함수 +def check_skill(words , skill) : + set_p = 0 ; + for c in words : + # 해당 스킬(c) 가 선행스킬 속 존재여부 파악 및 순번 확인 + idx = skill.find(c) + if idx < 0 : # ok + continue + elif idx == set_p : # ok + set_p +=1 + continue + else : + # 선행 스킬 순서 보다 더 이르게 w 스킬이 등장한 경우 + return False + return True + +def solution(skill, skill_trees): + answer = 0 + # 반복문올 skill_tree 속 선행스킬 조건에 충족하는 스킬 확인 및 개수 계산 + for skillset in skill_trees : + if check_skill(skillset , skill) : + answer += 1 + + return answer \ No newline at end of file diff --git "a/Hongjoo/\353\260\261\354\244\200/\354\210\250\353\260\224\352\274\255\354\247\2103.py" "b/Hongjoo/\353\260\261\354\244\200/\354\210\250\353\260\224\352\274\255\354\247\2103.py" index 5f452e9..864ff7f 100644 --- "a/Hongjoo/\353\260\261\354\244\200/\354\210\250\353\260\224\352\274\255\354\247\2103.py" +++ "b/Hongjoo/\353\260\261\354\244\200/\354\210\250\353\260\224\352\274\255\354\247\2103.py" @@ -39,3 +39,34 @@ visited[nx] = visited[cx] +1 q.append(nx) print(visited[K]) +import sys +from collections import deque +input = sys.stdin.readline +MAX = 100000 +N , K = map(int, input().split()) +visited = [MAX] * (MAX+1) # 방문 여부 +# 2. BFS로 N-> K 의 모든 경로 찾기 +t=0 +q = deque([N , t]) +visited[N]= 0 + + +while q : + cx= q.popleft() + ct =visited[cx] + for nx in (cx-1 , cx+1 , 2*cx) : + if 0 <= nx < MAX : + # 시간 업데이트 + if nx == 2*cx : + nt = ct + else : + nt = ct+1 + + if visited[nx] >= MAX : # 처음 도달 + q.append(nx) + visited[nx] = nt + else : # 중복& 최단 거리일때 + if nt < visited[nx] : + visited[nx] = nt + q.append(nx) +print(visited[K]) \ No newline at end of file