Skip to content

Commit 247decd

Browse files
committed
docs(readme): add run scripts section and generate xml script
1 parent c5839de commit 247decd

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ Each subdirectory within the `nowcoder` directory is named after a problem and i
5959
- `Test.java`: Test class file for the problem.
6060
- `TreeNode.java`: (If applicable) TreeNode class file for problems involving tree structures.
6161

62+
63+
### Run Scripts
64+
65+
```bash
66+
mvn exec:exec -Dproblem=p138 -X
67+
python scripts/generate_run_xml.py 138
68+
```
69+
6270
### UVa
6371

6472
Solved: 568, Submissions: 1776

scripts/Main.run.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Main" type="Application" factoryName="Application" nameIsGenerated="true">
3+
<option name="MAIN_CLASS_NAME" value="com.lzw.solutions.uva.p140.Main" />
4+
<module name="algorithm-solutions" />
5+
<option name="REDIRECT_INPUT" value="true" />
6+
<option name="INPUT_FILE" value="$PROJECT_DIR$/src/main/resources/uva/p140/1.in" />
7+
<extension name="coverage">
8+
<pattern>
9+
<option name="PATTERN" value="com.lzw.solutions.uva.p140.*" />
10+
<option name="ENABLED" value="true" />
11+
</pattern>
12+
</extension>
13+
<method v="2">
14+
<option name="Make" enabled="true" />
15+
</method>
16+
</configuration>
17+
</component>

scripts/generate_run_xml.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import argparse
2+
import os
3+
import xml.etree.ElementTree as ET
4+
5+
def generate_run_xml(problem_number):
6+
# Define paths
7+
script_dir = "scripts"
8+
run_dir = ".run"
9+
template_file = os.path.join(script_dir, "Main.run.xml")
10+
output_file = os.path.join(run_dir, f"MainP{problem_number}.run.xml")
11+
12+
# Ensure .run directory exists
13+
os.makedirs(run_dir, exist_ok=True)
14+
15+
# Read the template XML file
16+
with open(template_file, 'r') as file:
17+
xml_content = file.read()
18+
19+
# Replace p140 with the new problem number
20+
new_xml_content = xml_content.replace('p140', f'p{problem_number}')
21+
new_xml_content = new_xml_content.replace('name="Main"', f'name="MainP{problem_number}"')
22+
23+
# Write the new XML file
24+
with open(output_file, 'w') as file:
25+
file.write(new_xml_content)
26+
27+
print(f"Generated {output_file} for problem p{problem_number}")
28+
29+
def main():
30+
parser = argparse.ArgumentParser(description="Generate a new Main run XML file for a given problem number.")
31+
parser.add_argument("problem_number", type=str, help="Problem number (e.g., 138 for p138)")
32+
args = parser.parse_args()
33+
34+
generate_run_xml(args.problem_number)
35+
36+
if __name__ == "__main__":
37+
main()

src/main/java/com/lzw/solutions/uva/p138/Main.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.lzw.solutions.uva.p138;
22

33
import java.io.BufferedReader;
4-
import java.io.FileInputStream;
54
import java.io.IOException;
65
import java.io.InputStreamReader;
7-
import java.io.PrintStream;
86
import java.io.PrintWriter;
97

108
public class Main {

0 commit comments

Comments
 (0)