@@ -50,7 +50,7 @@ aims to do.
5050 ``` bash
5151 python main.py get [-l < language> ] < url-to-contest-page>
5252 ```
53- For instance, to generate testing code in C++ and Python (not supported yet) for
53+ For instance, to generate testing code in C++ and Python for
5454 [ Weekly Contest 163] ( https://leetcode.com/contest/weekly-contest-163 ) , run the command:
5555 ``` bash
5656 python main.py get -l cpp -l python -o projects/ https://leetcode.com/contest/weekly-contest-163
@@ -61,37 +61,52 @@ aims to do.
6161 - ` weekly-contest-163_python ` : Python code of problems in the contest.
6262
6363
64- ## Language-specific Instructions
64+ ## Instructions for Using Generated Code
6565
66- Currently, only C++ is supported, but Python support is planned.
66+ The project folder will contain one code file for each problem, and potentially other files required for compiling or
67+ testing. Problems are renamed to single uppercase letters (in the same order as on the web page) for simplicity.
68+
69+ The generated code contains a certain amount of boilerplate code for debugging. When submitting, remember to copy
70+ everything between the comments ` BEGIN SUBMIT ` and ` END SUBMIT ` .
71+
72+ You can add your custom code template to the generated code. Currently, this is only possible through modifying the code
73+ for LCHelper:
74+
75+ 1 . Find the code generator class for your language. The C++ generator is located in ` lchelper/codegen/cpp.py ` , and the
76+ Python generator in ` lchelper/codegen/python.py ` .
77+ 2 . Add a property named ` user_template_code ` , and make it return you code template. The syntax looks like this:
78+ ``` python
79+ @ property
80+ def user_template_code (self ) -> str :
81+ return r """
82+ template <typename ... Args>
83+ void my_amazing_debug_function( Args ... args) {
84+ // ...
85+ }
86+ """
87+ ```
88+ The property might already exist (it does in C++), in this case, feel free to replace it with your own.
89+
90+ See below for language-specific instructions. Currently, only C++ and Python are supported.
6791
6892### C++
6993
70- The generated C++ project builds using CMake. To setup the build system, run the following commands:
94+ The C++ project folder contains these additional files:
95+
96+ - ` CMakeLists.txt ` , CMake configuration for building the project.
97+ - ` _testing.h ` , a header-only library for comparing outputs.
98+ - ` _boilerplate.h ` , boilerplate code for LeetCode-specific stuff.
99+
100+ The generated C++ project builds using CMake. To compile the problems, run the following commands:
71101``` bash
72102cmake .
73103make
74104./A # to run tests for problem A
75105```
76106You can also use IDEs (e.g., JetBrains CLion) to automate the process.
77-
78- Note that problems are renamed to single uppercase letters (in the same order as on the web page) for simplicity.
79-
80- The generated code contains quite a lot of boilerplate code for debugging. When submitting, remember to copy everything
81- between the lines ` // BEGIN SUBMIT ` and ` // END SUBMIT ` .
82-
83- You can use your own template by modifying the ` TEMPLATE_CODE ` class variable in the file ` lchelper/codegen/cpp.py ` , but
84- you should only do so if you understand what you're doing. Remember to keep the following parts intact:
85-
86- - Comments ` // BEGIN * ` and ` // END * ` . The code generator needs them to know where to insert generated code.
87- - ` struct TreeNode ` , ` const int NONE ` , and ` TreeNode *_construct_tree() ` . These are required to handle tree inputs in
88- LeetCode format.
89- - ` #include "testing.h" ` . This include points to a tiny header-only library for testing your output.
90107
91108
92109## TODO
93110
94- - [ ] Python code generation
95111- [ ] Automatic submission
96- - [ ] Customized code templates
97112- [ ] Third-party login
0 commit comments