Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Last active March 8, 2018 12:35
Show Gist options
  • Save qkreltms/6fb0ca6aa39d61911302521b073b7629 to your computer and use it in GitHub Desktop.
Save qkreltms/6fb0ca6aa39d61911302521b073b7629 to your computer and use it in GitHub Desktop.
카카오톡 신입 공채 1, 2번 문제 python
import re
def kakao1_2(user):
p = re.compile('[0-9]+')
p2 = re.compile(r"[A-Z]+#*\**")
f = p.findall(user)
f2 = p2.findall(user)
result = [0] * 3
for i in range(3):
point = int(f[i])
bonus = f2[i][0]
if bonus == 'D':
result[i] = point**2
elif bonus == 'T':
result[i] = point**3
else:
result[i] = point
if len(f2[i]) >= 2:
option = f2[i][1]
if option == '*':
if i >= 1:
result[i-1] *= 2
result[i] *= 2
elif option == '#':
result[i] *= -1
return result[0] + result[1] + result[2]
assert(kakao1_2("1S2D*3T") == 37)
assert(kakao1_2("1D2S#10S") == 9)
assert(kakao1_2("1D2S0T") == 3)
assert(kakao1_2("1S*2T*3S") == 23)
assert(kakao1_2("1D#2S*3S") == 5)
assert(kakao1_2("1T2D3D#") == -4)
assert(kakao1_2("1D2S3T*") == 59)
assert(kakao1_2("10S10S10S") == 30)
assert(kakao1_2("10S10D10T*") == 2210)
assert(kakao1_2("10T*10T*10T*") == 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment