Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- import sys
- import time
- import socket
- host = "chall.ctf.bamboofox.tw"
- port = 10069
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((host, port))
- print('connect success')
- def main():
- print('main start')
- _ = s.recv(4096)
- # print(_.decode('utf-8'))
- s.send(bytes('EXCRUCIATING\n', 'utf-8'))
- _ = s.recv(4096)
- # print(_.decode('utf-8'))
- s.send(bytes('\n', 'utf-8'))
- cnt = 0
- while cnt < 32:
- cnt += 1
- print("Recv!")
- raw = s.recv(8192)
- print(f"raw = {raw}")
- raw = raw.decode('utf-8')
- if raw.find("Wrong answer") != -1 or raw.find("Time limit exceeded") != -1:
- exit(raw + " QAQ\n")
- l = raw.find("====== BEGIN INPUT =======") + 27
- r = raw.find("====== END OF INPUT ======") - 1
- print(f'Testcase #{cnt}\n{raw[l:r]}\n')
- with open('in.txt', 'w') as f:
- f.write(raw[l:r])
- os.system("./solve < in.txt | ./sparseElim | python crt.py > out.txt")
- with open('out.txt', 'r') as f:
- ans = f.read(1024)
- if ans.find('.') != -1:
- ans = ans[:ans.find('.')]
- ans = str(int(ans))
- print("ans =", ans)
- s.send(bytes(ans + '\n', 'utf-8'))
- print("OK!")
- time.sleep(0.01)
- ans = s.recv(1024)
- print(ans)
- main()
Advertisement
Add Comment
Please, Sign In to add comment