LibreOJ #103. 子串查找
生活随笔
收集整理的這篇文章主要介紹了
LibreOJ #103. 子串查找
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
二次聯(lián)通門 : LibreOJ #103. 子串查找
?
?
?
?
/*LibreOJ #103. 子串查找kmp*/ #include <cstdlib> #include <cstring> #include <cstdio>#define Max 1000900int next[Max];void Get_Next (char *line) {next[0] = -1;for (register int pos_1 = 0, pos_2 = -1, Len = strlen (line); pos_1 < Len; )if (pos_2 == -1 || line[pos_1] == line[pos_2]){pos_1 ++;pos_2 ++;next[pos_1] = pos_2;}elsepos_2 = next[pos_2];}int Answer;void Kmp (char *line, char *__txt) {int Len_txt = strlen (__txt);int Len_ = strlen (line);if (Len_txt < Len_){puts (0);exit (0);}for (register int pos_1 = 0, pos_2 = 0; pos_2 < Len_txt && pos_1 < Len_; ){if (pos_1 == -1 || line[pos_1] == __txt[pos_2]){pos_1 ++;pos_2 ++;}elsepos_1 = next[pos_1];if (pos_1 == Len_){Answer ++;pos_1 = next[pos_1];}} }char line[Max]; char __txt[Max];int main (int argc, char *argv[]) {scanf ("%s", __txt);scanf ("%s", line);Get_Next (line);Kmp (line, __txt);printf ("%d", Answer);return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/ZlycerQan/p/7076732.html
總結(jié)
以上是生活随笔為你收集整理的LibreOJ #103. 子串查找的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Uva 11600 期望DP
- 下一篇: 学习SpringMVC笔记——Intel