본문 바로가기
728x90

코딩테스트/Python78

프로그래머스 스쿨 - 바탕화면 정리(Python)(복습) answer = [0, 0, 0, 0] def solution(wallpaper): x, y = [], [] for i in range(len(wallpaper)): for j in range(len(wallpaper[i])): if wallpaper[i][j] == "#": y.append(i) x.append(j) lux = min(y) luy = min(x) rdx = max(y) + 1 rdy = max(x) + 1 answer = [lux, luy, rdx, rdy] return answer 2023. 10. 5.
프로그래머스 스쿨 - 달리기 경주(Python)(복습) answer = [] def solution(players, callings): pl = {} for i, j in enumerate(players): pl[j] = i for i in callings: a = pl[i] cur = players[a] pre = players[a-1] pl[cur] -= 1 pl[pre] += 1 players[a] = pre players[a-1] = cur answer = players return answer 2023. 10. 4.
프로그래머스 스쿨 - 공원 산책(Python)(복습) result = [] x = 0 y = 0 def solution(park, routes): for i in range(len(park)): for j in range(len(park[i])): if park[i][j] == 'S': x = j y = i break for route in routes: sx = x sy = y for step in range(int(route[2])): if route[0] == 'E' and sx != len(park[0])-1 and park[sy][sx+1] != 'X': sx += 1 if step == int(route[2])-1: x = sx elif route[0] == 'W' and sx != 0 and park[sy][sx-1] != 'X': sx -= .. 2023. 10. 3.
프로그래머스 스쿨 - 개인정보 수집 유효기간(Python)(복습) today = "2022.05.19" terms = ["A 6", "B 12", "C 3"] privacies = ["2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C"] def time_convert(t) : year, month, day = map(int, t.split('.')) return year * 12 * 28 + month * 28 + day # 1달 28일 def solution(today, terms, privacies): term_dict = {} today = time_convert(today) answer = [] for term in terms : name, period = term.split() term_dict[nam.. 2023. 10. 2.
프로그래머스 스쿨 - 최고의 집합(Python) def solution(n, s): answer = [] result = [] if n > s: result.append(-1) else: count1 = s // n for i in range(n): result.append(count1) index = len(result) - 1 for i in range(s % n): result[index] += 1 index -= 1 answer = result return answer result = [] result.append(-1) print(result) 2023. 10. 1.
프로그래머스 스쿨 - 피자 나눠 먹기(3)(Python) def solution(slice, n): answer = ((n-1) // slice) + 1 return answer 2023. 9. 30.
728x90