BF算法

//BF算法
#include <iostream>

using namespace std;

int BF(char S[], char T[])
{
    int index = 0, i = 0, j = 0;
    while (S[i] != '\0' && T[j] != '\0')
    {
        if (S[i] == T[j])
        {
            i ++;
            j ++;
        }
        else 
        {
            index ++;
            i = index;
            j = 0;
        }
    }
    if (T[j] == '\0')
        return index + 1;
    else 
        return 0;
}

int main()
{
    char S[100] = "abcdefg";
    char T[100] = "bc";
    cout << BF(S, T) << endl;
    return 0;
}
posted on 2023-05-06 16:54  逆袭怪  阅读(26)  评论(0编辑  收藏  举报