#include
#include
using namespace std;
int fan(string &str,string &str1)
{
int ct = 0;
for (int i = 0, j = 1;str[j] != '\0';i++, j++)
{
if (str[i] == str1[0] && str[j] == str1[1])
ct++;
}
return ct;
}
int main()
{
string str;
string str2;
cin >> str;
cin.clear();
cin >> str2;
cout<<fan(str, str2);
return 0;
}
本文介绍了一种在C++中实现的字符串匹配算法,通过遍历字符串并比较子串来计算匹配次数。此算法适用于需要查找特定子串出现频率的场景。
1726

被折叠的 条评论
为什么被折叠?



