Created
May 26, 2014 06:54
-
-
Save sota1235/352ca2c399611386539a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import socket | |
| host = 'rg-ctf.yagihashoo.com' | |
| port = 'secret' | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| sock.connect((host,port)) | |
| while True: | |
| string = sock.recv(524288) | |
| if string != "": | |
| print string | |
| else: | |
| break | |
| if '=>' in string: | |
| q = string[:-4].split(' ') | |
| stack = [] | |
| print q | |
| print len(q) | |
| while len(q) > 0: | |
| # print q, stack | |
| stack.append(q.pop(0)) | |
| if not stack[-1].isdigit() and len(stack[-1]) == 1: | |
| obj = stack.pop() | |
| num = float(stack.pop(-1)) | |
| if obj == '+': | |
| ans = float(stack.pop()) + num | |
| elif obj == '-': | |
| ans = float(stack.pop()) - num | |
| elif obj == '*': | |
| ans = float(stack.pop()) * num | |
| elif obj == '/': | |
| ans = float(stack.pop()) / num | |
| stack.append(ans) | |
| # print q | |
| if stack[0] < 0 and stack[0] - int(stack[0]) != 0: | |
| # print stack[0] | |
| stack[0] -= 1 | |
| sock.sendall(str(int(stack[0])) + '\n') | |
| sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment