-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
51 lines (50 loc) · 1.32 KB
/
script.py
File metadata and controls
51 lines (50 loc) · 1.32 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
import sys, subprocess
n = len(sys.argv)
if (n > 3):
raise Exception("Too many args!");
elif (n < 3):
raise Exception("Too less args!");
else:
templateFile = open("./template.cpp")
template = templateFile.read()
type = sys.argv[2]
link = sys.argv[1]
i = -1
cnt = 0
idx = 0
if type == 'c':
while cnt != 3:
if (link[i] == '/'):
cnt+=1
if cnt == 2:
idx = i
i-=1
i+=2
elif type == 'p':
while cnt != 2:
if (link[i] == '/'):
cnt+=1
if cnt == 1:
idx = i
i-=1
i+=2
elif type == 'g':
while cnt != 3:
if (link[i] == '/'):
cnt+=1
if cnt == 2:
idx = i
i-=1
i+=2
template = '// ' + link + '\n' + template
problemNumber = link[i:idx]
problemLetter = link[-1]
if (link[-1] >= '0' and link[-1] <= '9'):
problemLetter = link[-2] + link[-1]
filepath = './Codeforces/' + problemNumber + problemLetter + '.cpp'
if type == 'g':
filepath = './Codeforces/Gym/' + problemNumber + problemLetter + '.cpp'
file = open(filepath, 'w')
file.write(template)
file.close()
subprocess.run(['code', filepath])