字串專題

2022-05-16 21:52:12 字數 1755 閱讀 7246

kmp模板:

#include #include #include #include #include using namespace std;

int ls, lt, nxt[1000005];

char t[1000005], s[1000005];

int main()

for(int i = 1, j = 0; i <= ls; i++)

for(int i = 1; i <= lt; i++) printf("%d ", nxt[i]);

return 0;

}

manacher模板:

#include #include #include #include #include using namespace std;

int ls, p[23000100], ans;

char s[23000100];

int main()

cout << ans << endl;

return 0;

}

trie模板:

#include #include #include #include #include using namespace std;

struct triet[510005];

int tot, rt;

int new()

void change(char *s, int ls)

t[now].cnt++;

} int query(char *s, int ls)

if(t[now].cnt == 0) return -1;

if(t[now].bj == 1) return 1;

t[now].bj = 1;

return 0;

} }tr;

int z, ls, n;

char s[510005];

int main()

scanf("%d", &n);

for(int i = 1; i <= n; i++)

}

ac自動機:

trie圖(ac自動機無fail指標,孩子如果為空直接指到相應的該去的差了好幾次的有兒子的fail上)、fail樹

注意判是否出現過要沿著\(fail\)找一遍。

struct ac_machinet[3000005];

int rt, tot;

int new()

void clear()

void change(char *s, int ls)

t[now].bj = ++bh;

} void init()

} }int query(char *s, int ls)

if(ans == t[p].cnt) v.push_back(t[p].bj);

p = t[p].nxt;

}} return ans;

}}acm;

字尾陣列模板:

#include #include #include #include #include using namespace std;

struct suffix_array

for(int i = 1; i <= ls; i++)

}}sa;

char s[2000005];

int main()

字串專題

created on 2019年12月1日 author hp 擷取字串 str2 我是迪迦奧特曼 str3 str2 5 str4 str2 0 len str2 2 print str3,str4 擷取的字串如果不存在,會出現異常,可以用try.except捕捉異常 try str5 str2 ...

字串專題

給定乙個字串,你的任務是計算這個字串中有多少個回文子串。具有不同開始位置或結束位置的子串,即使是由相同的字元組成,也會被視作不同的子串。示例1 輸入 abc 輸出 3 解釋 三個回文子串 a b c 示例 2 輸入 aaa 輸出 6 解釋 6個回文子串 a a a aa aa aaa 解法 1 動態...

字串專題

1.double ceil double x 求大於 x 的最小的數,即向上取整函式 includeusing namespace std intmain 2.a 65 z 90 a 97 z 122 3.字串刪除 c 從string中刪除所有的某個特定字元 超好 includeusing name...