-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloj.py
More file actions
executable file
·69 lines (68 loc) · 2.56 KB
/
Copy pathloj.py
File metadata and controls
executable file
·69 lines (68 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
import requests
import os
import re
import sys
if __name__ == '__main__':
if len(sys.argv) == 2:
id = sys.argv[1]
else :
id = (input('请输入题目编号(LOJ): '))
Url = "https://loj.ac/problem/" + id
DataUrl = "https://loj.ac/problem/{0}/testdata".format(id)
Page = requests.get(Url)
DataPage = requests.get(DataUrl)
Html = str(Page.content.decode('utf-8'))
DataHtml = str(DataPage.content.decode('utf-8'))
CanBeSolve = Html.find('<a href=\"javascript:history.go(-1)\">')
if CanBeSolve == -1:
CanBeSolve = True
print('此题是否可做: 裆燃啦!')
else:
CanBeSolve = False
print('ZLJ!此题不可做!')
exit()
Memory = int(Html.split(' MiB</span>')[0].split('内存限制:')[-1])
Time = int(Html.split(' ms</span>')[0].split('时间限制:')[-1])
DataHtml = DataHtml.split('<tbody>')[1].split('</tbody>')[0]
Reg = r'[0-9a-zA-z.]*\d+.in'
DataList = re.findall(Reg, DataHtml)
NameList = []
for i in DataList:
NameList.append(i.replace(".in",""))
print("以下是题目信息...")
print("Time: {0} ms\nMemory: {1} MiB".format(Time, Memory))
os.system("rm -rf data")
os.system("mkdir data")
os.system("cd data")
print("正在下载数据包...")
os.system("axel -a -o {0}.zip https://loj.ac/problem/{0}/testdata/download".format(id))
print("下载完成...正在解压数据包...")
os.system("unzip -q {0}.zip -d data/".format(id))
os.system("rm {0}.zip".format(id))
print("解压完成啦w")
# CppFileName
os.system("rm temp 2> /dev/null")
os.system("ls > temp")
CppFileName = "test.cpp"
with open("temp", "r") as ls:
for line in ls:
try:
temp = line.split('.')[1]
except IndexError:
continue
if temp == 'cpp\n':
CppFileName = line.rstrip()
os.system("rm temp")
print("正在生成配置文件...")
with open("config.txt", "w") as Config:
Config.write("File Name: {0}\n".format(CppFileName))
Config.write("Input Name: {0}\n".format('#.in'))
Config.write("Output Name: {0}\n".format('#.out'))
temp = "#: "
for i in NameList:
temp += i + ' '
Config.write(temp + '\n')
Config.write("Max Running Time: {0}\n".format(Time))
Config.write("Max Running Memory: {0}".format(Memory))
print("配置文件生成完成啦,由于LOJ不公开data_rule,自动生成的config可能会存在问题,请谨慎使用qwq")