Compare commits
2 Commits
23adf96c96
...
4e6373ac46
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e6373ac46 | |||
| 1859a0eb18 |
27
.obsidian/workspace.json
vendored
27
.obsidian/workspace.json
vendored
@@ -36,23 +36,9 @@
|
||||
"icon": "lucide-file",
|
||||
"title": "2026-2-3 周二"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ba9747c8bf5f1e5f",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "webviewer",
|
||||
"state": {
|
||||
"url": "https://share.note.youdao.com/ynoteshare/index.html?id=a66c778ce8c6e4ee03608e493e59ba7a&type=notebook&_time=1768473840238#/WEB4f51ebc698a96e5cc1a682b2fb7b683d",
|
||||
"title": "CQ2605",
|
||||
"mode": "webview"
|
||||
},
|
||||
"icon": "globe-2",
|
||||
"title": "CQ2605"
|
||||
}
|
||||
}
|
||||
],
|
||||
"currentTab": 2
|
||||
"currentTab": 1
|
||||
}
|
||||
],
|
||||
"direction": "vertical"
|
||||
@@ -119,12 +105,13 @@
|
||||
"state": {
|
||||
"type": "outline",
|
||||
"state": {
|
||||
"file": "Diary/2026-2/2026-2-3 周二.md",
|
||||
"followCursor": true,
|
||||
"showSearch": false,
|
||||
"searchQuery": ""
|
||||
},
|
||||
"icon": "lucide-list",
|
||||
"title": "大纲"
|
||||
"title": "2026-2-3 周二 的大纲"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -275,10 +262,12 @@
|
||||
"remotely-save:Remotely Save": false
|
||||
}
|
||||
},
|
||||
"active": "ba9747c8bf5f1e5f",
|
||||
"active": "a699df623da488e3",
|
||||
"lastOpenFiles": [
|
||||
"Diary/2026-2/2026-2-3 周二.md",
|
||||
"YueQian/相关网站.md",
|
||||
"Diary/2026-2/2026-2-3 周二.md",
|
||||
"Collection/KMP算法.md",
|
||||
"YueQian/Homework/~WRL0004.tmp",
|
||||
"BlogWebsite/Article/Obsidian使用飞牛WebDAV实现多端同步.md",
|
||||
"YueQian/Homework/~$2数组与指针作业.doc",
|
||||
"Diary/2026-2/2026-2-2 周一.md",
|
||||
@@ -299,7 +288,6 @@
|
||||
"Diary/2026-1/2026-1-20 周二.md",
|
||||
"Diary/2026-1/2026-1-19 周一.md",
|
||||
"Diary/2026-1/2026-1-31 周六.md",
|
||||
"YueQian/Homework/~$数组3.docx",
|
||||
"Diary/2026-1/2026-1-30 周五.md",
|
||||
"YueQian/Homework/1-29作业.md",
|
||||
"YueQian/Homework/1.19-已完成.md",
|
||||
@@ -311,7 +299,6 @@
|
||||
"Diary/2026-1/2026-1-28 周三.md",
|
||||
"Collection/连~都忘记了的小知识.md",
|
||||
"Excalidraw/Drawing 20260122.md",
|
||||
"Collection/KMP算法.md",
|
||||
"Diary/2026-1/2026-1-27 周二.md",
|
||||
"Diary/2026-1/2026-1-26 周一.md",
|
||||
"Diary/2026-1/2026-1-25 周日.md",
|
||||
|
||||
@@ -23,27 +23,18 @@ KMP算法的时间复杂度为O(n+m),其中n是主串的长度,m是模式串
|
||||
```c
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// 函数原型声明
|
||||
|
||||
void computeLPSArray(char *pat, int M, int *lps);
|
||||
|
||||
void KMPSearch(char *pat, char *txt);
|
||||
|
||||
int main() {
|
||||
|
||||
char text[] = "ABABDABACDABABCABAB";
|
||||
|
||||
char pattern[] = "ABABCABAB";
|
||||
|
||||
printf("Text: %s\n", text);
|
||||
|
||||
printf("Pattern: %s\n", pattern);
|
||||
|
||||
KMPSearch(pattern, text);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -60,25 +51,27 @@ int i = 1;
|
||||
|
||||
while (i < M) {
|
||||
|
||||
if (pat[i] == pat[len]) {
|
||||
if (pat[i] == pat[len]) {
|
||||
|
||||
len++;
|
||||
len++;
|
||||
|
||||
lps[i] = len;
|
||||
lps[i] = len;
|
||||
|
||||
i++;
|
||||
i++;
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
if (len != 0) {
|
||||
if (len != 0) {
|
||||
|
||||
len = lps[len - 1];
|
||||
len = lps[len - 1];
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
lps[i] = 0;
|
||||
lps[i] = 0;
|
||||
|
||||
i++;
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
@@ -117,25 +110,16 @@ i++;
|
||||
}
|
||||
|
||||
if (j == M) {
|
||||
|
||||
printf("Pattern found at index %d \n", i - j);
|
||||
|
||||
j = lps[j - 1];
|
||||
|
||||
} else if (i < N && pat[j] != txt[i]) {
|
||||
|
||||
if (j != 0)
|
||||
|
||||
j = lps[j - 1];
|
||||
|
||||
printf("Pattern found at index %d \n", i - j);
|
||||
j = lps[j - 1];
|
||||
}
|
||||
else if (i < N && pat[j] != txt[i]) {
|
||||
if (j != 0)
|
||||
j = lps[j - 1];
|
||||
else
|
||||
|
||||
i = i + 1;
|
||||
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user