Simple_PS

  • Lv2 프로그래머스(Programmers)[Python][파이썬] 주식 가격
    """ 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/42584 """ # 풀이 과정 def solution(prices): p = prices result = [] for a in range(len(prices) - 1): num = p[a] count = 0 flag = False for b in range(a + 1, len(p)): count += 1 if p[b] < num: result.append(count) flag = True break if flag == False: result.append(count) result.append(0) return result
  • Lv1 프로그래머스(Programmers)[Mysql] 평균 일일 대여 요금 구하기
    """ 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/151136 """ """ 풀이 과정 # 반올림 함수 round SELECT round(avg(DAILY_FEE)) from CAR_RENTAL_COMPANY_CAR where CAR_TYPE ="SUV" """
  • Lv1 프로그래머스(Programmers)[Mysql] 자동차 대여 기록에서 장기/단기 대여 구분하기
    """ 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/151138 """ """ 풀이 과정 select HISTORY_ID,CAR_ID,Date_format(START_DATE,"%Y-%m-%d") "START_DATE",Date_format(END_DATE,"%Y-%m-%d") "END_DATE", CASE when datediff(END_DATE, START_DATE) >= 29 then "장기 대여" else "단기 대여" END "RENT_TYPE" from CAR_RENTAL_COMPANY_RENTAL_HISTORY where START_DATE Like "2022-09%" order by HISTORY_ID desc """
  • Lv1 프로그래머스(Programmers)[Mysql] 특정 옵션이 포함된 자동차 리스트 구하기
    출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/157343 풀이 과정 select * from CAR_RENTAL_COMPANY_CAR # %를 통하여 앞뒤로 네비게이션이 들어간 목록을 찾는다 where OPTIONS like "%네비게이션%" order by CAR_ID desc
  • Lv3 프로그래머스(Programmers)[Python][파이썬] 아이템 줍기
    """ 출처: 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/87694 """ # 풀이 과정 """ 사각형들의 모든 점들을 알아낸 후 주어진 점을 이동시키는 것을 실행 그 중 사각형 내부에 있는 점 거르기+중복점 제거 생각 아이디어 그리고 매 순간 그 중 아이템이 있는 점에 도달하는 지 여부 확인+ 최단 거리 구하기 # 주어진 조건들 통하여 알 수 있는 정보: 주어진 점들의 좌표들, 선분들의 좌표, 외부에 있는 점들의 좌표, """ from collections import deque def solution(rectangle, characterX, characterY, itemX, itemY): # sol(내부의 선분등을 제대로 표현하기 힘듬) # # 내부에 있지 않은 점 # check=set([]) # for x1,y1,x2,y2 in rectangle: # new=[] # for v1,w1,v2,w2 in rectangle: # if v1<x1<v2 and w1<y1<w2: # new.append((x1,y1)) # if v1<x2<v2 and w1<y1<w2: # new.append((x2,y1)) # if v1<x1<v2 and w1<y2<w2: # new.append((x1,y2)) # if v1<x2<v2 and w1<y2<w2: # new.append((x2,y2)) # check=check|(set([(x1,y1),(x1,y2),(x2,y1),(x2,y2)])-set(new)) # 이동시킬 맵 m = [[0] * (101) for _ in range(101)] dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] # 사각형 위의 모든 점 new = [] for x1, y1, x2, y2 in rectangle: for x in [x1 * 2, x2 * 2]: for y in range(y1 * 2, (y2) * 2 + 1): new.append((x, y)) for y in [y1 * 2, y2 * 2]: for x in range(x1 * 2, (x2) * 2 + 1): new.append((x, y)) new = set(new) # 중복 제거 # 사각형 내부의 점 구분 check = [] for x1, y1, x2, y2 in rectangle: for x, y in new: if x1 * 2 < x < x2 * 2 and y1 * 2 < y < y2 * 2: check.append((x, y)) road = new - set(check) for x, y in road: m[x][y] = 1 # m[characterX][characterY]="start" # m[itemX][itemY]="destination" q = [(characterX * 2, characterY * 2)] # 방문처리 확인 v = [[0] * 101 for _ in range(101)] plus = [] # 거리 result = 0 # bfs while q: x, y = q.pop() # 방문 처리 v[x][y] = 1 if x == itemX * 2 and y == itemY * 2: return result // 2 for nx, ny in zip(dx, dy): if 0 <= x + nx <= 100 and 0 <= y + ny <= 100 and v[x + nx][y + ny] == 0 and m[x + nx][y + ny] == 1: plus.append((x + nx, y + ny)) if len(q) == 0: plus = list(set(plus)) q += plus result += 1 plus = []
  • Lv2 프로그래머스(Programmers)[Python][파이썬] 조이스틱
    """ 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/42860 """ # 풀이 과정 # 틀린 이유 pop을 해버리면 도중에 다른 곳으로 이동할 때 A로 변한 부분을 거쳐갈 때 거리 커서 계산이 안됨 # 좌우 이동을 dfs로 풀이 # dfs from collections import deque import copy eng = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # 커서 옮기는 방향 _ 왼쪽 def left(x, y, z): if len(x) == x.count("A"): return x, y, z while True: y += 1 z -= 1 if x[z] != "A": t = eng.find(x[z]) break if t >= 13: t = 26 - t y += t x[z] = "A" return x, y, z # 커서 옮기는 방향 _ 오른쪽 def right(x, y, z): if len(x) == x.count("A"): return x, y, z while True: y += 1 z += 1 if x[z] != "A": t = eng.find(x[z]) break if t >= 13: t = 26 - t y += t x[z] = "A" return x, y, z def solution(name): start = "A" * len(name) check = deque(list(name)) result = [] # 첫번째_커서 시작 위치 k = eng.find(check[0]) if k >= 13: k = 26 - k count = k check[0] = "A" if len(check) == check.count("A"): return count q = deque([check]) count_q = deque([k]) point_q = deque([0]) # 방향키 위치 while q: one = q.popleft() two = count_q.popleft() three = point_q.popleft() one_right = copy.deepcopy(one) two_right = copy.deepcopy(two) three_right = copy.deepcopy(three) left_q, left_num, left_p = left(one, two, three) right_q, right_num, right_p = right(one_right, two_right, three_right) if len(left_q) == left_q.count("A"): result.append(left_num) else: q.append(left_q) count_q.append(left_num) point_q.append(left_p) if len(right_q) == right_q.count("A"): result.append(right_num) else: q.append(right_q) count_q.append(right_num) point_q.append(right_p) return min(result) if len(result) > 0 else 0
  • Lv3 프로그래머스(Programmers)[Python][파이썬] 스티커 모으기(2)
    """ 출처 프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/12971 """ # 풀이 과정 from collections import deque def solution(sticker): s = deque(sticker) if len(s) == 0 or len(s) == 1: return max(s) dp_one = [0] * len(s) dp_one[0] = s[0] dp_one[1] = max(s[0], s[1]) for i in range(2, len(s) - 1): dp_one[i] = max(dp_one[i - 1], dp_one[i - 2] + s[i]) k = s.popleft() s.append(k) one = max(dp_one) dp_two = [0] * len(s) dp_two[0] = s[0] dp_two[1] = max(s[0], s[1]) for i in range(2, len(s) - 1): dp_two[i] = max(dp_two[i - 1], dp_two[i - 2] + s[i]) two = max(dp_two) return max(one, two)
  • Lv2 프로그래머스(Programmers)[Python][파이썬] 점프와 순간 이동
    """ 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/12980 """ # 풀이 과정 def solution(n): ans = 0 check = n while check >= 1: if check % 2 == 0: check = int(check / 2) else: check -= 1 ans += 1 return ans
  • Lv3 프로그래머스(Programmers)[Python][파이썬] 스타 수열
    """ 출처:프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/70130 """ # 풀이 과정 """ 생각방향 # 부분수열의 모든 경우의 수를 비트마스크로 나타낸 후 스타수열 거르기 """ from itertools import combinations from collections import Counter def solution(a): result = 0 k = Counter(a) k = dict(k) # 최대 9개의 수를 데이터를 정렬하기에 많은 시간 소요 안됨 k_new = sorted(k.items(), key=lambda x: (x[1])) # 최대 숫자 모음 체크 check = [] for i, j in k_new: check.append(i) # 들어있는 숫자 횟수 n = 0 while check: # 스타수열의 교집합이 될 수 s = check.pop() # 스타수열 star = [] for num in range(len(a)): i = a[num] if len(star) % 2 == 0: star.append(i) else: if star[-1] != s and i != s: continue elif star[-1] == s and i != s: star.append(i) elif star[-1] != s and i == s: star.append(i) if len(star) % 2 == 1: star.pop() result = max(result, len(star)) if len(check) > 0: # 이후 만들어질 최대 개수 보다 이미 많을 경우 더이상 무의하기는거 확인 if k[check[-1]] * 2 < result: return result return result
  • Lv2 프로그래머스(Programmers)[Python][파이썬] 전화번호 목록
    """ 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/42577 """ # 풀이과정 def solution(phone_book): p = phone_book p.sort() for a in range(len(p) - 1): if p[a] in p[a + 1][0:len(p[a])]: return False else: continue return True
  • << 6 7 8 9 10 11 12 13 14 15 16 >>