teamnote default

This commit is contained in:
2026-06-03 09:20:51 +09:00
commit f50ed902fe
65 changed files with 6033 additions and 0 deletions

17
source/String/KMP.cpp Normal file
View File

@@ -0,0 +1,17 @@
int fail[N]; // N : s의 최대 길이
vi kmp(char obj[], char s[]) {
vi ret;
for(int i = 1, j = 0; s[i]; i++) {
fail[i] = 0;
while(j > 0 and s[i] != s[j]) j = fail[j-1];
if(s[i] == s[j]) fail[i] = ++j;
}
for(int i = 0, j = 0; obj[i]; i++) {
while(j > 0 and obj[i] != s[j]) j = fail[j-1];
if(obj[i] == s[j]) {
if(s[j+1]) j++;
else ret.push_back(i-j), j = fail[j];
}
}
return ret;
}