コード例 #1
0
/**
 * Doesn't work with string containing null bytes
 */
bool isSubstring(const std::string& haystack, const std::string& needle) {
	auto pi = prefixFunction(needle + '\0' + haystack);
	for (auto value: pi) {
		if (value == needle.size()) {
			return true;
		}
	}
	return false;
}
コード例 #2
0
ファイル: KMP.cpp プロジェクト: moni-roy/ACM-SOLUTIONs
int KMP(string s,string p) {
    int ret=0,j=0,ln=s.size();;
    prefixFunction(p);
    for(int i=0; i<ln; i++) {
        while(j && s[i]!=p[j]) j=pre[j-1];
        if(s[i]==p[j]) j++;
        if(j==(int)p.size()) ret++;
    }
    return ret;
}