标签:crt efi include cab ack cin ios stack define
http://acm.zjnu.edu.cn/DataStruct/showproblem?problem_id=1005
题解:kmp模板题。
如何理解kmp?
背下来就好了
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string> #include<string.h> #include<stack> #include<iostream> using namespace std; const int maxn = 1e5 + 5; char t[maxn]; char p[maxn]; int tlen, plen; int k[maxn]; bool kmp() { int i = 1,j = 0; while (i < plen) { if (p[i] == p[j])k[i] = j+1, i++, j++; else { if (j == 0)k[i] = 0,i++; else j = k[j - 1]; } }//k数组更新 i = 0, j = 0; while (j < plen&&i < tlen) { if (t[i] == p[j])i++, j++; else { if (j == 0)i++; else j = k[j - 1]; } } if (j == plen)return 1; else return 0; } int main() { scanf("%s", t); tlen = strlen(t); int n; cin >> n; while (n--) { scanf("%s", p); plen = strlen(p); if (kmp())puts("yes"); else puts("no"); } cin >> n; } /* abxabcabcaby 1 abcaby */
标签:crt efi include cab ack cin ios stack define
原文地址:https://www.cnblogs.com/SuuT/p/8886264.html