목록문제/프로그래머스_파이썬 (13)
sm 기술 블로그
def solution(record): answer = [] userDict = dict() for val in record: tmp = val.split(" ") if(tmp[0] == "Enter"): answer.append(tmp[1] + "님이 들어왔습니다.") userDict[tmp[1]] = tmp[2] elif(tmp[0] == "Leave"): answer.append(tmp[1] + "님이 나갔습니다.") else: userDict[tmp[1]] = tmp[2] for i in range(len(answer)): userIdTmp = answer[i] userId = userIdTmp[0:userIdTmp.index("님")] answer[i] = answer[i].replace(use..
dict = [chr(ord("A")+i) for i in range(0,26)] def solution(msg): answer = [] first = 0 last = 0 tmp = 0 while last < len(msg): if msg[first:last+1] in dict: tmp = dict.index(msg[first:last+1]) last += 1 else: answer.append(tmp + 1) dict.append(msg[first:last+1]) first = last answer.append(tmp + 1) return answer 문제요약 LZW(Lempel–Ziv–Welch) 압축을 구현을 구현하시오. 설명 dict = [chr(ord("A")+i) for i in range(0..
import math def feesCal(fees, time): if(time < fees[0]): return fees[1] return fees[1] + math.ceil(((time - fees[0]) / fees[2])) * fees[3] def timeCal(recordsSplit): totalTime = dict() for i in recordsSplit: tmp = list(map(int, i[0].split(":"))) if(i[2] == "IN"): try: totalTime[i[1]][1] += (tmp[0]*60 + tmp[1]) totalTime[i[1]][2] = 1 except: totalTime[i[1]] = [0,(tmp[0]*60 + tmp[1]), 1] else : to..
import math def change(n, k): rev_base = '' while n > 0: n, mod = divmod(n, k) rev_base += str(mod) return rev_base[::-1] # 역순인 진수를 뒤집어 줘야 원래 변환 하고자하는 base가 출력 def prime(M): M = str(M) while(M.find("00") != -1): M = M.replace("00","0") tmp = M.split("0") cnt = 0 for val in tmp: if(val == "1" or len(val) == 0): continue val = int(val) is_prime = 0 R = int(math.sqrt(val)) for j in range(2, R+1): i..