예제 #1
0
int main() {
    char text[] = "przeczyscilem zlew, bo go olewalem. teraz ide zrobic sobie lewatywe. polewka lew nalewka lwy. trololo";
    char wzorzec[] = "lew";
    printf("%s\n",text);
    KMP_search(text,wzorzec);
    return 0;
}
예제 #2
0
파일: KMP.cpp 프로젝트: alibekU/algorithms
/*
 KMP_count
 return number of occurences of 'pattern'
 in 'text' with overplaps permitted.
 */
int KMP_count(string text, string pattern){
    int count = 0, pos = 0, temp = 0;
    
    while(pos < text.length()){
        temp = KMP_search(text.substr(pos), pattern);
        if (temp == -1) {
            break;
        }
        pos += temp +1;
        count++;
    }
    return  count;
}
예제 #3
0
파일: KMP.cpp 프로젝트: alibekU/algorithms
vector<int> KMP_search_all(string text, string pattern){
    vector<int> result;
    int pos = 0, temp = 0;
    while(pos < text.length()){
        temp = KMP_search(text.substr(pos), pattern);
        if (temp == -1) {
            break;
        }
        pos += temp;
        result.push_back(pos);
        pos ++;
    }
    return result;
}