공부/코딩테스트 51

[프로그래머스] 숫자 문자열과 영단어(파이썬, 자바)

내 답 def solution(s): dict={'zero':'0','one':'1','two':'2','three':'3','four':'4','five':'5','six':'6','seven':'7','eight':'8','nine':'9'} result='' temp='' for i in s: if i.isdigit(): result+=i continue temp+=i if temp in dict: result+=dict[temp] temp='' return int(result) 다른 사람의 답 num_dic = {"zero":"0", "one":"1", "two":"2", "three":"3", "four":"4", "five":"5", "six":"6", "seven":"7", "eight":"..

[프로그래머스] 멀쩡한 사각형(파이썬)

나의 답 : def solution(w,h): s=w*h if w%h==0 or h%w==0: return s-max(w,h) else: a=w b=h if w < h: (w, h) = (h, w) while h != 0: (w, h) = (h, w % h) return s-w*((a/w)+(b/w)-1) 다른 사람의 답 : def gcd(a,b): return b if (a==0) else gcd(b%a,a) def solution(w,h): return w*h-w-h+gcd(w,h) 최대공약수를 생각해낸 것이 뿌듯했다. 문제 출처 : https://programmers.co.kr/learn/courses/30/lessons/62048

[프로그래머스] 2018 KAKAO BLIND RECRUITMENT 다트 게임(파이썬)

나의 답 : def solution(dartResult): s=[] score=[] s+=dartResult[0] answer = 0 for i in dartResult[1:]: if i=='0' and s[-1]=='1': s[-1] = '10' continue if i.isdigit(): if s[-1].isalpha(): s.append('-') s.append(i) elif i=='S' or i=='D' or i=='T': s.append(i) elif i=='*' or i=='#': s.append(i) print(s) for i in range(len(s)): print(score) if s[i].isdigit(): score.append(int(s[i])) elif s[i] == 'S': s..