-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert.py
More file actions
56 lines (43 loc) · 1.75 KB
/
convert.py
File metadata and controls
56 lines (43 loc) · 1.75 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
"""
This script helps to convert the problems which has testcases format
compatible with Themis by Le Minh Hoang & Do Duc Dong to the format
this project uses
Just place problem folders to convert/ in the same directory as this
script and run it
"""
import os
if not os.path.exists("convert"):
exit()
entries = os.scandir("convert")
for entry in entries:
if not entry.is_dir():
continue
print(f"Converting {entry.name}...")
os.makedirs(f"problems/{entry.name}", exist_ok=True)
count = 0
scan = os.scandir(f"convert/{entry.name}")
for i in scan:
if not i.is_dir():
continue
if not i.name.lower().startswith("test"):
continue
try:
with open(f"convert/{entry.name}/{i.name}/{entry.name}.inp", "rb") as f:
_inp = f.read()
with open(f"convert/{entry.name}/{i.name}/{entry.name}.out", "rb") as f:
_out = f.read()
os.makedirs(f"problems/{entry.name}/testcases", exist_ok=True)
with open(f"problems/{entry.name}/testcases/{count + 1}.in", "wb") as f:
f.write(_inp)
with open(f"problems/{entry.name}/testcases/{count + 1}.out", "wb") as f:
f.write(_out)
count += 1
except Exception as e:
print(e)
if not os.path.exists(f"problems/{entry.name}/config.cfg"):
with open(f"problems/{entry.name}/config.cfg", "w", encoding="utf-8") as f:
f.write("TEST_CASES=" + str(count) + "\n")
# Optional
f.write("TIME_LIMIT=1\n")
f.write("MEMORY_LIMIT=1024\n")
print(f"Converted {entry.name} with {count} testcases")