Skip to content

feat(CustomCode_ZH.md):增加cpp常用配置推荐和VelocityTool.java中函数的介绍 #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/CustomCode-cpp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 55 additions & 16 deletions doc/CustomCode_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
- [English Document](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode.md)
- [中文文档](#配置)
<p align="center"><img src="https://cdn.jsdelivr.net/gh/shuzijun/leetcode-editor@master/doc/customConfig-100.gif" alt="loacl" style="width: auto;height: auto;max-width: 90%; max-height: 90%;"></p>


## 配置
<p align="center"><img src="https://cdn.jsdelivr.net/gh/shuzijun/leetcode-editor@master/doc/config-3.0.jpg" alt="config" style="width: auto;height: auto;max-width: 90%; max-height: 90%;"></p>

- **Custom code template**: 开启使用自定义模板,否则使用默认生成格式
- **CodeFileName**: 生成文件的名称,默认为题目标题
- **CodeTemplate**: 生成题目代码的内容,默认为题目描述和题目代码
Expand All @@ -17,32 +17,71 @@
- **${question.frontendQuestionId}**:题目编号,例如:1
- **${question.content}**:题目描述内容
- **${question.code}**:题目代码部分
- **$!velocityTool.camelCaseName(str)**:一个函数,用来将字符串转化为驼峰样式
- **$!velocityTool.camelCaseName(str)**:一个函数,用来将字符串转换为大驼峰样式
- **$!velocityTool.smallCamelCaseName (str)**:一个函数,用来将字符串转换为小驼峰样式
- **$!velocityTool.snakeCaseName(str)**:一个函数,用来将字符串转换为蛇形样式
- **$!velocityTool.toPinyinAndTrims(str)**:将汉字转为为拼音并去除所有空格
- 更多工具参考[VelocityTool.java](https://github.com/shuzijun/leetcode-editor/blob/master/src/main/java/com/shuzijun/leetcode/plugin/utils/VelocityTool.java)

## 注意
在生成的自定义代码中包含两行关键信息:
- `leetcode submit region begin(Prohibit modification and deletion)`:提交到leetcode进行验证的代码开始标记
- `leetcode submit region end(Prohibit modification and deletion)`:提交到leetcode进行验证的代码结束标记
这两行标记标示了提交到leetcode服务器进行验证的代码范围,在此范围内只允许有出现与题目解答相关的内容,出现其他内容可能导致leetcode验证不通过。
除了此范围内,其他区域是可以任意填写的,内容不会提交到leetcode,可以增加一些可以本地调试的内容,例如:import java.util.Arrays;
所以,这两行内容是不能被删除和修改的,否则将识别不到提交的内容。
这两行标记标示了提交到leetcode服务器进行验证的代码范围,在此范围内只允许有出现与题目解答相关的内容,出现其他内容可能导致leetcode验证不通过。
除了此范围内,其他区域是可以任意填写的,内容不会提交到leetcode,可以增加一些可以本地调试的内容,例如:import java.util.Arrays;
所以,这两行内容是不能被删除和修改的,否则将识别不到提交的内容。

## JAVA常用配置
可参考示例:[示例工程](https://github.com/shuzijun/leetcode-question)
CodeFileName:

```java
$!velocityTool.camelCaseName(${question.titleSlug})
```
TemplateConstant:
```java
${question.content}
${question.content}

package com.shuzijun.leetcode.editor.en;
public class $!velocityTool.camelCaseName(${question.titleSlug}){
public static void main(String[] args) {
Solution solution = new $!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
}
${question.code}
}
package com.shuzijun.leetcode.editor.en;
public class $!velocityTool.camelCaseName(${question.titleSlug}){
public static void main(String[] args) {
Solution solution = new $!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
}
${question.code}
}
```

## C++常用配置

CodeFileName:

```
Leetcode_$!velocityTool.toPinyinAndTrims(${question.frontendQuestionId})_$!velocityTool.toPinyinAndTrims(${question.titleSlug})
```

TemplateConstant:

```cpp
${question.content}
\#include <bits/stdc++.h>

using namespace std;
#set($solutionId = ${question.frontendQuestionId})
#set($solutionId = $solutionId.replaceAll(" ", "_"))
#set($solutionId = $solutionId.replaceAll("[\\u4e00-\\u9fa5-]", "")) ## 删除中文字符和"-"符号

namespace solution${solutionId}{
${question.code}
}

using namespace solution${solutionId};
int main() {
Solution solution;

return 0;
}
```

效果如下图所示:

<img src="CustomCode-cpp.png" alt="CustomCode-cpp" style="zoom: 60%;" />