Skip to content

Instantly share code, notes, and snippets.

@theoremoon
Created Nov 8, 2015
Embed
What would you like to do?
SECCON福島大会 サイバー甲子園 Programming 200pt
import re
S = """1lp(34) 6eqq0(28) 1e1c(15) / 9i7(28) * + 12db(31) * -12221111(3) 1211201(4) 13ldi(29) 14610(7) / * + - 1733k(21) 613401(8) * 2r5a(31) - * 1amp5(27) 403603(7) * aq53(32) + + 71148(11) 1g890(19) h5ha(19) * + ao13(31) 9501(15) * 6h8k(36) - 29dc2(15) 323030330(4) 8581b(12) * + * + * -51e(21) 5346(9) 99b(16) * + 680k(25) * 211222240(5) b68(23) / 682(13) 908(21) * + - dh01(25) 169b(15) 111011000000110011(2) * + * egl(24) 1884342(9) 37g(21) / * 1020020(4) + 9fe1(17) * zy(36) 121jg9(23) 5t0(35) / a93(22) * + - - + 61179(20) 450363(8) -e8g(22) 1232201(4) 7c0b6(21) hag(22) / * + * + e9a5(17) 13191 onqd(27) * + -1045 5c4(24) 1486(11) * + 5eig(19) * -100101010110(2) 2ka(31) 14123(5) * + + * + 1012211102010(3) nrk(32) * 341365(9) + 168193(14) 63a(20) * 868044(9) - 63505(11) 1d555(15) 313432(9) * + * + -bb1(18) 7rl(33) 2e2ug(32) 17b2(14) / * + nd0(35) * 1i43e(24) + e8wb(35) 1b25(34) 134442303(5) * + * 2601(8) 1200002(3) 2el(29) * + 23103133(4) * afg5(23) - - * + * 1538h(27) 2d55c(14) * 6b3p(35) - 15qm7(28) 33013203(4) * f3f8(16) + 14323(5) 49j8k(21) 20044(6) / 3in(31) * + 8ij9(26) * 2104326(7) + * + 213021243(5) 12b65(14) * 2164603(8) + 2ebcb(16) 43004(6) 1100100011000011001(2) * + * 7snt(34) 7l7g(25) * 2b90b(16) - - * 5461(8) 2kk(31) 3cm(33) * + 110101100010000(2) * -9694 eim(26) 10011000011010111011101(2) e53(22) / * + - 307281(12) 30w(36) * 92593 - 8lq(34) 1d1d0e(17) 11b5(21) / * 100121120(3) + 156557(9) 32t(34) 2ol(29) 3735 * + * + * + + - """.split(" ")
ans = []
matcher = re.compile("(\w+)\((\w+)\)")
cur = 0
opstack = []
for c in S:
r = matcher.search(c)
if r:
if (c[0] == '-'):
ans.append('-' + str(int(r.group(1), int(r.group(2)))))
else:
ans.append(str(int(r.group(1), int(r.group(2)))))
else:
ans.append(c)
ans2 = []
for a in ans:
if '' is not a:
ans2.append(a)
ops = {"+": lambda a, b: b + a,
"-": lambda a, b: b - a,
"*": lambda a, b: b * a,
"/": lambda a, b: b / a}
def calc(stack, st):
if st in ops:
stack.append(ops[st](stack.pop(), stack.pop()))
else:
stack.append(int(st))
return stack
oka = reduce(calc, ans2, [])[-1]
buf=hex(oka)[2:-1]
hoge = re.compile("(..)")
ls = hoge.split(buf)
l2 = []
for x in ls:
if x is not '':
l2.append(chr(int(x, 16)))
print("".join(l2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment