-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathauto.py
More file actions
68 lines (43 loc) · 1.27 KB
/
auto.py
File metadata and controls
68 lines (43 loc) · 1.27 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
from string import Template
import os
def main():
number = raw_input('Enter problem number: ')
link = raw_input('Enter problem url: ')
problem = link.split('/')[-2]
title = problem.replace('-', ' ').title()
# Write README.md
template = Template("""
### $No. $Title
[Lintcode](http://lintcode.com/en/problem/$tag/)
| [Online Solution](http://jiuzhang.com/solutions/$tag/)
| [Java Solution]($No.$tag.java)
| [Cpp Solution]($No.$tag.cpp)
| [Blog](http://blog.liuk.ai/$No-$tag/)
""")
post_template = Template("""
$No. $Title
#### Problem
[Practice on Lintcode](http://lintcode.com/en/problem/$tag/)
**Example**
#### Solution
*Implementation*
Time complexity `O(n)`
```language-java line-numbers
```
*Implementation Note*
""")
try:
f = open('README.md', 'a+')
except:
f = open('README.md', 'w')
f.write(template.substitute({'No': number, 'tag': problem, 'Title': title}))
f.write(post_template.substitute({'No': number, 'tag': problem, 'Title': title}))
f.close()
# Create files
pwd = os.getcwd()
fh = open('%s/%s.%s.java' % (pwd, number, problem), 'w')
fh.close()
fh = open('%s/%s.%s.cpp' % (pwd, number, problem), 'w')
fh.close()
if __name__ == "__main__":
main()