每日一题4.9.1
每日一题4.9.1
剪花布条
解题思路: 长字符串中寻找子串的问题,尝试用过哈希,发现不行,用find在字符串中查找
代码实现:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1, str2;
while (cin>>str1>>str2)
{
int res = 0;
size_t pos = 0;
while ((pos = str1.find(str2,pos))!= string::npos)
{
pos += str2.size();
++res;
}
cout << res << endl;
}
return 0;
}