[Python3] ์ˆซ์ž ๋ฌธ์ž์—ด๊ณผ ์˜๋‹จ์–ด ๋‹ค๋ฅธ ํ’€์ด - ๋”•์…”๋„ˆ๋ฆฌ
ยท
๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
์Œ. ๋„ˆ๋ฌด ์–ด๋ ต๊ฒŒ ์ƒ๊ฐํ–ˆ๋‚˜. ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ํ’€์ด๋ฅผ ๋ดค๋Š”๋ฐ ์ •๊ทœํ‘œํ˜„์‹์€ ๋„ˆ๋ฌด ์“ธ๋ฐ์—†์—ˆ๋‹ค.ใ…Žใ…Ž.. ๋‚˜์ฒ˜๋Ÿผ ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ์ ‘๊ทผํ•˜์‹ฌ. (๊ทผ๋ฐ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ ๋‚ด ํ’€์ด๋Š” ๊ตณ์ด ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ํ•„์š”๋„ ์—†์—ˆ๋‹ค.. ๋ฐ˜์„ฑ๋ฐ˜์„ฑ..) 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) ๊ทธ๋ƒฅ ๋ฐ”๋กœ replace๋กœ ํ•ด๋ฒ„๋ฆฌ๋ฉด ..
[Python3] 2021 ์นด์นด์˜ค ์ฑ„์šฉ์—ฐ๊ณ„ํ˜• ์ธํ„ด์‹ญ, ์ˆซ์ž ๋ฌธ์ž์—ด๊ณผ ์˜๋‹จ์–ด
ยท
๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
s๊ฐ€ ์˜๋ฏธํ•˜๋Š” ์›๋ž˜ ์ˆซ์ž returnํ•˜๊ธฐ. โœ๏ธ ํ’€์ด ๋ฐฉ๋ฒ• ๊ทธ๋ƒฅ ์˜์–ด๋Š” ์ˆซ์ž๋กœ ๋ฐ”๊พธ๊ณ , ์ˆซ์ž๋Š” ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋ฉด ๋˜์ง€ ์•Š๋‚˜? โœ๏ธ 1์ฐจ ์ฝ”๋“œ import re def solution(s): word = {'zero':0, 'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8, 'nine':9} keylist = list(word.keys()) if s.isdigit() == True: answer = int(s) else: for i in range(len(keylist)): isin = s.find(keylist[i]) if isin >= 0: s= s[0:isin] + str(i) + s[isin+1:] newS =..
[Python3] ์ •๊ทœํ‘œํ˜„์‹
ยท
๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
import re def solution(dartResult): bonus = {'S' : 1, 'D' : 2, 'T' : 3} option = {'' : 1, '*' : 2, '#' : -1} p = re.compile('(\d+)([SDT])([*#]?)') dart = p.findall(dartResult) for i in range(len(dart)): if dart[i][2] == '*' and i > 0: dart[i-1] *= 2 dart[i] = int(dart[i][0]) ** bonus[dart[i][1]] * option[dart[i][2]] answer = sum(dart) return answer '๋‹คํŠธ๊ฒŒ์ž„' ๋ฌธ์ œ์˜ ๋‹ค๋ฅธ ๋ถ„๋“ค์˜ ํ’€์ด๋ฅผ ๋ณด๊ณ  ์žˆ๋Š”๋ฐ ์ •๊ทœํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•œ ํ•ด๋‹ต์ด ์žˆ์–ด ..
[Python3] 2018 KAKAO BLIND RECRUITMENT ๋‹คํŠธ๊ฒŒ์ž„
ยท
๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
โœ๏ธ๋ฌธ์ œ ์ •๋ฆฌ #3๋ฒˆ์˜ ๊ธฐํšŒ ํ•ฉ (0~10์ ) #Single(S)-์ ์ˆ˜ 1์ œ๊ณฑ, Double(D) - 2์ œ๊ณฑ, Triple(T) - 3์ œ๊ณฑ #์Šคํƒ€์ƒ(*) - ํ•ด๋‹น&๋ฐ”๋กœ ์ „ ์ ์ˆ˜ ๊ฐ 2๋ฐฐ, ์ฒซ ๊ธฐํšŒ์˜ ๊ฒฝ์šฐ ์Šคํƒ€์ƒ ์ ์ˆ˜๋งŒ ๋‘๋ฐฐ, ์ค‘์ฒฉ์€ 4๋ฐฐ #์•„์ฐจ์ƒ(#) - ํ•ด๋‹น ์ ์ˆ˜ ๋งˆ์ด๋„ˆ์Šค, ์Šคํƒ€์™€ ์ค‘์ฒฉ ๊ฒฝ์šฐ -2 #์ ์ˆ˜|๋ณด๋„ˆ์Šค|[์˜ต์…˜]์˜ ๋ฌธ์ž์—ด 3์„ธํŠธ โœ๏ธ์˜ˆ์ œ ์ •๋ฆฌ ์˜ˆ์ œ ์ผ๋ถ€ ์ •๋ฆฌ 1S 2D* 3T ( 1^1 )*2 + (2^2)*2 + 3^3 -> ์Šคํƒ€์ƒ๋•Œ๋ฌธ์— ์•ž, ์ค‘๊ฐ„๊ฐ’ 2๋ฐฐ์”ฉ 37 1D 2S# 10S 1^2 + 2^1 * (-1) + 10^1 -> ์•„์ฐจ์ƒ๋•Œ๋ฌธ์— ๋งˆ์ด๋„ˆ์Šค 9 1S* 2T* 3S (1^1) * 2 * 2 + (2^3) * 2 + 3^1 ->์Šคํƒ€์ƒ ์ค‘์ฒฉ 23 โœ๏ธ๋ฌธ์ œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์ˆซ์ž ๊ธฐ์ค€์œผ๋กœ ์ž˜๋ผ์„œ ๋ฆฌ..