목록전체 글 (183)
on my way

https://school.programmers.co.kr/learn/courses/30/lessons/70129# 1트def solution(s): cnt0, cntR = 0, 0 while s != "1": cntR += 1 zero = len([1 for d in s if d == "0"]) cnt0 += zero s = format(len(s) - zero, 'b') return cntR, cnt0# 리팩토링def solution(s): cnt0, cntR = 0, 0 while s != "1": cntR += 1 cnt0 += s.count("0") s = bin(len(s.rep..

[프로그래머스 코딩테스트 연습] 3진법 뒤집기 (Python3) def solution(n): answer = '' while n>0: n, mod = divmod(n, 3) answer += str(mod) return int(answer,3) 10진법 -> n진법 변화 방법을 알면 쉽게 풀 문젠데 (난 몰랐다 ㅎ)n이 0될때까지 divmod 함수를 사용해 3씩 나누어 mod를 구한다.각각 더해진 mod들을 원래 3진법 방식으로는 [::-1]로 뒤집어야하지만 이 문제에서는 어차피 뒤집으므로,바로 int( , 3) 로 3진법에서 10진법으로 변환하여 출력

https://school.programmers.co.kr/learn/courses/30/lessons/12930# def solution(s): answer = "" for word in s.split(' '): for i, w in enumerate(word): answer += w.lower() if i%2 else w.upper() answer += " " return answer[:-1] 반례input: "a a "output: "A A " 반례때문에 그냥 split() 했다가 좀 헤맸다. def solution(s): return ' '.join( ''.join(w.lowe..

https://www.acmicpc.net/problem/5622 # 리팩토링 전import sysfrom collections import defaultdictdial = ["ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"]tel = defaultdict(int)num = sys.stdin.readline().strip()count = 0for n in num: if not tel[n]: for i, d in enumerate(dial): if n in d: tel[n] = i+3 break count += tel[n]print(count)# 리팩토링 후import s..

https://www.acmicpc.net/problem/2675import sysT = int(sys.stdin.readline())for _ in range(T): R, S = sys.stdin.readline().split() R = int(R) for s in S: print(s*R, end='') print()