-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_solution.py
More file actions
executable file
·68 lines (54 loc) · 2.39 KB
/
create_solution.py
File metadata and controls
executable file
·68 lines (54 loc) · 2.39 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
#!/usr/bin/env python3
import sys
import os
import shutil
import subprocess
def main():
if len(sys.argv) != 3:
print("Usage: python create_solution.py <platform> <problem_id>")
print("Example: python create_solution.py uva 12166")
print("platform: uva or codeforces")
sys.exit(1)
platform = sys.argv[1]
problem_id = sys.argv[2].strip()
if platform not in ['uva', 'codeforces']:
print("Invalid platform. Use 'uva' or 'codeforces'.")
sys.exit(1)
# Assume running from project root
base_dir = os.getcwd()
src_java = os.path.join(base_dir, 'src', 'main', 'java', 'com', 'lzw', 'solutions', 'sample', 'pjava_sample_buf', 'Main.java')
if not os.path.exists(src_java):
print(f"Template not found: {src_java}")
sys.exit(1)
target_java_dir = os.path.join(base_dir, 'src', 'main', 'java', 'com', 'lzw', 'solutions', platform, f'p{problem_id}')
target_java = os.path.join(target_java_dir, 'Main.java')
os.makedirs(target_java_dir, exist_ok=True)
# Copy and update package
shutil.copy2(src_java, target_java)
with open(target_java, 'r') as f:
content = f.read()
old_package = 'com.lzw.solutions.sample.pjava_sample_buf'
new_package = f'com.lzw.solutions.{platform}.p{problem_id}'
content = content.replace(old_package, new_package)
with open(target_java, 'w') as f:
f.write(content)
# Resources dir for 1.in
resources_dir = os.path.join(base_dir, 'src', 'main', 'resources', platform, f'p{problem_id}')
input_file = os.path.join(resources_dir, '1.in')
os.makedirs(resources_dir, exist_ok=True)
# Read from macOS clipboard (pbpaste)
try:
clipboard_content = subprocess.check_output(['pbpaste']).decode('utf-8').strip()
if clipboard_content:
with open(input_file, 'w') as f:
f.write(clipboard_content)
print(f"[OK] Created {target_java}")
print(f"[OK] Created {input_file} from clipboard")
else:
print(f"[WARN] Created {target_java}, but clipboard empty - add 1.in manually")
except subprocess.CalledProcessError:
print(f"[ERR] Failed to read clipboard. Created {target_java}, add {input_file} manually.")
except Exception as e:
print(f"[ERR] Error with clipboard: {e}. Created {target_java}, add {input_file} manually.")
if __name__ == '__main__':
main()