코딩테스트 연습 - 숫자 문자열과 영단어
네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자
programmers.co.kr
풀이
def solution(s):
answer = s
num_s = {'zero':0, 'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8, 'nine':9}
for item in num_s.items():
answer = answer.replace(item[0], str(item[1]))
return int(answer)
다른 사람 풀이
num_dic = {"zero":"0", "one":"1", "two":"2", "three":"3", "four":"4", "five":"5", "six":"6", "seven":"7", "eight":"8", "nine":"9"}
def solution(s):
answer = s
for key, value in num_dic.items():
answer = answer.replace(key, value)
return int(answer)
'Engineering WIKI > Programmers' 카테고리의 다른 글
[프로그래머스] 소수 만들기 (0) | 2022.04.01 |
---|---|
[프로그래머스] 내적 (0) | 2022.04.01 |
[프로그래머스] 음양 더하기 (0) | 2022.04.01 |
[프로그래머스] 없는 숫자 더하기 (0) | 2022.04.01 |
[프로그래머스] 크레인 인형뽑기 게임 (0) | 2022.04.01 |
[프로그래머스] 키패드 누르기 (0) | 2022.04.01 |
[프로그래머스] 로또의 최고순위와 최저순위 (0) | 2022.04.01 |
[프로그래머스] 신고 결과 받기 (0) | 2022.04.01 |