Skip to content

Commit 6a64cb9

Browse files
authored
Merge pull request #38 from rennzhang/feat-lang
fix: fixed i18n for "Code"
2 parents ab4c42d + ada249c commit 6a64cb9

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

‎src/codeTemplates/grapth.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module.exports = () => ({
1515
{
1616
language: "py",
1717
desc: `
18-
19-
比如一个图是这样的:
18+
${t("Locale.codeTemplate.graph.item1_desc1")}
19+
2020
2121
\`\`\`
2222
E -- 1 --> B -- 1 --> C -- 1 --> D -- 1 --> F
@@ -25,7 +25,8 @@ E -- 1 --> B -- 1 --> C -- 1 --> D -- 1 --> F
2525
-------- 2 ---------> G ------- 1 ------
2626
\`\`\`
2727
28-
我们使用邻接矩阵来构造:
28+
${t("Locale.codeTemplate.graph.item1_desc2")}
29+
2930
3031
\`\`\`py
3132
G = {
@@ -47,6 +48,7 @@ import heapq
4748
4849
def dijkstra(graph, start, end):
4950
# 堆里的数据都是 (cost, i) 的二元祖,其含义是“从 start 走到 i 的距离是 cost”。
51+
# The data in the heap consists of tuples (cost, i), where it signifies "the distance from start to i is cost".
5052
heap = [(0, start)]
5153
visited = set()
5254
while heap:
@@ -79,18 +81,24 @@ def dijkstra(graph, start, end):
7981
language: "py",
8082
text: `
8183
# graph 是邻接矩阵,n 是顶点个数
84+
# The graph is represented as an adjacency matrix, where n represents the number of vertices.
85+
8286
# graph 形如: graph[u][v] = w
87+
# graph is like: graph[u][v] = w
8388
def floyd_warshall(graph, n):
8489
dist = [[float("inf") for _ in range(n)] for _ in range(n)]
8590
8691
for i in range(n):
8792
for j in range(n):
8893
dist[i][j] = graph[i][j]
8994
95+
# 将顶点k与所有其他顶点(i, j)进行比较
9096
# check vertex k against all other vertices (i, j)
9197
for k in range(n):
98+
# 循环遍历图数组的行
9299
# looping through rows of graph array
93100
for i in range(n):
101+
# 循环遍历图数组的列
94102
# looping through columns of graph array
95103
for j in range(n):
96104
if (
@@ -116,7 +124,9 @@ def floyd_warshall(graph, n):
116124
{
117125
language: "py",
118126
text: `
127+
# 如果不存在,返回-1
119128
# return -1 for not exsit
129+
# 如果存在,返回 dis map,dis[v]表示从点s到点v的最小花费
120130
# else return dis map where dis[v] means for point s the least cost to point v
121131
def bell_man(edges, s):
122132
dis = defaultdict(lambda: math.inf)
@@ -245,7 +255,8 @@ def PrimsAlgorithm(l): # noqa: E741
245255
set_position(positions[start], temp)
246256
247257
top_to_bottom(heap, m, size, positions)
248-
258+
259+
# 如果最小堆中任意节点的值减小,则更新函数
249260
# Update function if value of any node in min-heap decreases
250261
def bottom_to_top(val, index, heap, position):
251262
temp = position[index]
@@ -283,10 +294,16 @@ def PrimsAlgorithm(l): # noqa: E741
283294
return temp
284295
285296
visited = [0 for i in range(len(l))]
286-
Nbr_TV = [-1 for i in range(len(l))] # Neighboring Tree Vertex of selected vertex
297+
# 所选顶点的邻近树顶点
298+
# Neighboring Tree Vertex of selected vertex
299+
Nbr_TV = [-1 for i in range(len(l))]
300+
# 部分树的探索顶点到邻近顶点的最小距离
287301
# Minimum Distance of explored vertex with neighboring vertex of partial tree
302+
# 以图表形式呈现
288303
# formed in graph
289-
Distance_TV = [] # Heap of Distance of vertices from their neighboring vertex
304+
# 堆顶点到相邻顶点的距离
305+
# Heap of Distance of vertices from their neighboring vertex
306+
Distance_TV = []
290307
Positions = []
291308
292309
for x in range(len(l)):
@@ -339,8 +356,9 @@ if __name__ == "__main__": # pragma: no cover
339356
text: `
340357
def topologicalSort(graph):
341358
"""
359+
Kahn算法是使用广度优先搜索(BFS)来找到有向无环图(Directed Acyclic Graph)的拓扑排序的算法。
342360
Kahn's Algorithm is used to find Topological ordering of Directed Acyclic Graph
343-
using BFS
361+
using BFS.
344362
"""
345363
indegree = [0] * len(graph)
346364
queue = collections.deque([])
@@ -369,7 +387,7 @@ def topologicalSort(graph):
369387
else:
370388
print(topo)
371389
372-
390+
# 图的邻接表
373391
# Adjacency List of Graph
374392
graph = {0: [1, 2], 1: [3], 2: [3], 3: [4, 5], 4: [], 5: []}
375393
topologicalSort(graph)

‎src/codeTemplates/preSum.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,75 @@
22
const { t } = require("../locales");
33
const pre1dJSCode = `
44
// 建立
5+
// build
56
const pre = [0]
67
for(const num of nums) {
78
pre.push(pre[pre.length-1] + num)
89
}
910
// 使用,等价于 nums[i] + nums[i + 1] + ... + nums[j]
11+
// Use, equivalent to nums[i] + nums[i + 1] + ... + nums[j]
1012
pre[j+1] - pre[i]
1113
`;
1214

1315
const pre1dPythonCode = `
1416
# 建立
17+
# build
1518
pre = []
1619
for num in nums:
1720
pre.append(pre[-1] + num)
1821
# 使用,等价于 nums[i] + nums[i + 1] + ... + nums[j]
22+
# Use, equivalent to nums[i] + nums[i + 1] + ... + nums[j]
1923
pre[j+1] - pre[i]
2024
`;
2125

2226
const pre2dPythonCode = `
2327
m,n = len(matrix), len(matrix[0])
2428
# 建立
29+
# build
2530
pre = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
2631
for i in range(1, m+1):
2732
for j in range(1, n +1):
2833
pre[i][j] = pre[i-1][j]+ pre[i][j-1] - pre[i-1][j-1] + matrix[i-1][j-1]
2934
3035
# 使用,等价于以(x1,y1)为矩阵左上角以(x2,y2)为矩阵右下角的所有格子的和
36+
# Use, equivalent to the sum of all cells with (x1, y1) as the upper left corner and (x2, y2) as the lower right corner
3137
pre[x2+1][y2+1] + pre[x1][y1] - pre[x1][y2+1] - pre[x2+1][y1]
3238
`;
3339

3440
const diff1dPythonCode = `
3541
# 差分数组一般是对一个数组的若干区间进行若干次加减操作,求最终更新后的数组。
36-
d = [0] * n # 差分数组
37-
ans = [0] * n # 经过若干次操作后的最终数组
38-
for start, end, inc in updates: # updates 就是一系列操作,start 是开始坐标,end 是结束坐标,inc 是增加的值(可为负数)。
42+
# The difference array is generally to perform several addition and subtraction operations on several intervals of an array to obtain the finally updated array.
43+
44+
# 差分数组
45+
# difference array
46+
d = [0] * n
47+
# 经过若干次操作后的最终数组
48+
# the final array after several operations
49+
ans = [0] * n
50+
# updates 就是一系列操作,start 是开始坐标,end 是结束坐标,inc 是增加的值(可为负数)。
51+
# updates is a series of operations, start is the starting coordinate, end is the ending coordinate, and inc is the added value (can be negative).
52+
for start, end, inc in updates:
3953
d[start] += seats
4054
if end+1 < n: d[end+1] -= inc
4155
return list(accumulate(d))
4256
`;
4357

4458
const diff2dPythonCode = `
45-
matrix = [[0] * n for _ in range(n)] # 经过若干次操作后的最终数组
46-
diff = [[0] * (n+1) for _ in range(n+1)] # 差分数组
47-
for r1, c1, r2, c2, inc in updates: # updates r1,c1 是左上角坐标,r2, c2 是右下角坐标,inc 是增加的值(可为负数)。
59+
# 经过若干次操作后的最终数组
60+
# the final array after several operations
61+
matrix = [[0] * n for _ in range(n)]
62+
# 差分数组
63+
# difference array
64+
diff = [[0] * (n+1) for _ in range(n+1)]
65+
# updates r1,c1 是左上角坐标,r2, c2 是右下角坐标,inc 是增加的值(可为负数)。
66+
# updates r1,c1 is the upper left corner coordinate, r2, c2 is the lower right corner coordinate, and inc is the added value (can be negative).
67+
for r1, c1, r2, c2, inc in updates:
4868
diff[r1][c1] += inc
4969
diff[r1][c2+1] -= inc
5070
diff[r2+1][c1] -= inc
51-
diff[r2+1][c2+1] += inc # 别忘记了,由于我们在两个地方对减去 1, 因此在右下角会多减去一个,加上去即可。
71+
# 别忘记了,由于我们在两个地方对减去 1, 因此在右下角会多减去一个,加上去即可。
72+
# Don't forget, because we subtract 1 in two places, one more will be subtracted in the lower right corner, so add it back.
73+
diff[r2+1][c2+1] += inc
5274
for i in range(n):
5375
for j in range(n):
5476
matrix[i][j] = diff[i][j]

‎src/locales/en.js

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ const en = {
200200
graph: {
201201
title: "Graph",
202202
item1: "dijkstra(single-source greedy shortest path)",
203+
item1_desc1: "For example, consider a graph like this:",
204+
item1_desc2: "We construct it using an adjacency matrix:",
203205
item2: "floyd_warshall(multi-source dynamic programming shortest path)",
204206
item3: "Bellman–Ford(single-source dynamic programming shortest path)",
205207
item4:
@@ -295,6 +297,7 @@ const en = {
295297

296298
explanationTemplate: {
297299
name: "Explanation Template",
300+
code: "Code",
298301
goToTheWebsiteToUse: "Go to the website to use",
299302
problemAddress: "Problem Address",
300303
problemDesc: "Problem Description",

‎src/locales/zh.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ const zh = {
195195
graph: {
196196
title: "图",
197197
item1: "dijkstra(单源贪心最短路径)",
198+
item1_desc1: "比如一个图是这样的:",
199+
item1_desc2: "我们使用邻接矩阵来构造:",
198200
item2: "floyd_warshall(多源动态规划最短路径)",
199201
item3: "Bellman–Ford(单源动态规划最短路径)",
200202
item4: "Kruskal(又称加边法,是一种最小生成树算法)",
@@ -208,7 +210,6 @@ const zh = {
208210
item3: "寻找最右边的满足条件的值",
209211
item4: "寻找最左插入位置",
210212
item5: "寻找最右插入位置",
211-
212213
},
213214
BFS: {
214215
item1: "带层信息",
@@ -236,7 +237,7 @@ const zh = {
236237
title: "前缀树",
237238
item1: "标准前缀树",
238239
},
239-
240+
240241
uf: {
241242
title: "并查集",
242243
item1: "不带权并查集",
@@ -287,6 +288,7 @@ const zh = {
287288

288289
explanationTemplate: {
289290
name: "题解模板",
291+
code: "代码",
290292
goToTheWebsiteToUse: "去网站使用",
291293
problemAddress: "题目地址",
292294
problemDesc: "题目描述",

‎src/solutionTemplate/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ${desc}
114114
115115
- ${keyword}
116116
117-
## Code
117+
## ${t("Locale.explanationTemplate.code")}
118118
119119
- ${t("Locale.explanationTemplate.languageSupport")}${displayLanguage(
120120
language

0 commit comments

Comments
 (0)