목록전체 글 (24)
ol-rlo-zl

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 (dict 이용) 및 결과 def solution(players, callings): ranks = dict(zip(players,range(len(players)))) for c in callings: # c: 따라잡은 사람 r = ranks[c] # r: 따라잡은 사람의 원래 등수 p = players[r-1] # p: 따라잡힌 사람 ranks[c] -= 1 ranks[p] += 1 players[r-1] = c players[r] = p return players 시행착오 (시간초과 68.8점..

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 def solution(id_list, report, k): reports = {i : 0 for i in id_list} # 유저별 신고 받은 횟수 res = {i : 0 for i in id_list} # 유저별 받을 메일 수 # 유효한 신고들에 대하여, 유저별로, 신고받은 횟수 구하기 (즉, reports 구하기) for r in set(report): user, bad = r.split() reports[bad] += 1 # 유효한 신고들에 대하여, 유저별로, 정지당한 유저를 신고한 횟수 구..

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 def solution(numbers, hand): result = '' left = '*' right = '#' phone = [['1','2','3'],['4','5','6'],['7','8','9'],['*','0','#']] def distance(start,end): start_x, start_y, end_x, end_y = 0, 0, 0, 0 for i in range(4): for j in range(3): if phone[i][j] == start: start_x = i start_y..

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 def solution(park, routes): dx = {'N':-1 ,'S':1 ,'W':0 ,'E':0 } dy = {'N':0 ,'S':0 ,'W':-1 ,'E':1 } # 시작좌표 [x,y] x = -1 for p in park: x += 1 if 'S' in p: y = p.index('S') break # 한 칸씩 이동해보면서 끝까지 조건 만족하면, 명령 수행 for r in routes: op, n = r.split() for i in range(1,int(n)+1): nx = x ..

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 첫 번째 풀이 def solution(n, lost, reserve): lost.sort() res = n - len(lost) del_lost = [] for l in lost: if l in reserve: res += 1 reserve.remove(l) del_lost.append(l) lost = list(set(lost) - set(del_lost)) for l in lost: if l-1 in reserve: res += 1 reserve.remove(l-1) elif l+1 in reserv..

문제 프로그래머스 lv0 - 옹알이(1) 프로그래머스 lv2 - 옹알이(2) 풀이 - 옹알이 (1) # SOL 1 def solution(babbling): cnt = 0 for b in babbling: for w in ["aya", "ye", "woo", "ma"]: if w in b: # 가능한 발음이 있다면 b = b.replace(w,' ',1) # 1번만 repeat if len(b.strip()) == 0: cnt += 1 return cnt # SOL 2 def solution(babbling): cnt = 0 for b in babbling: for w in ["aya", "ye", "woo", "ma"]: if w*2 not in b: # 가능한 발음이 연속되지 않는다면 b = b.re..

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 중복순열 product 이용 from itertools import product def solution(word): res = [] for i in range(1,6): for i in product(['A', 'E', 'I', 'O', 'U'], repeat=i): res.append(''.join(i)) return sorted(res).index(word) + 1 결과

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 def solution(files): answer = [] for f in files: head, number, tail = '', '', '' number_check = False for i in range(len(f)): if f[i].isdigit(): number += f[i] number_check = True elif not number_check: head += f[i] else: tail += f[i:] break answer.append([head, number, tail]) ans..

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 나의 풀이 (리스트 이용) def solution(dirs): dic = {'U':[0,1],'D':[0,-1],'R':[1,0],'L':[-1,0]} before = [0,0] road = [] for d in dirs: nx = before[0] + dic[d][0] ny = before[1] + dic[d][1] after = [nx,ny] if nx in range(-5,6) and ny in range(-5,6): if before+after not in road and after+before ..

문제 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 def solution(land): for i in range(1,len(land)): for j in range(4): land[i][j] += max(land[i-1][:j] + land[i-1][j+1:]) return max(land[-1]) 결과