题解 | #统计字符串中子串出现的次数#

统计字符串中子串出现的次数

https://www.nowcoder.com/practice/9eb684f845a446f3b121472de2ea75cd

#include <iostream>
#include <string>
using namespace std;


int main()
{
    char str[100];
    char substr[100];

    cin >> str >> substr ;

    // by find to find the same substring
    string str1(str);
    string str2(substr);
    int postion = 0;
    int count = 0;

    while (str1.find(str2, postion) != string::npos)
    {
        ++count;
        postion = str1.find(str2, postion) + 1;
    }

    cout << count << endl;

    return 0;
}


使用find()函数
全部评论

相关推荐

smile丶snow:感觉可以加一些ai相关的内容吧。现在面试很少能逃掉这些问题。羡慕里面感觉缺少一个项目背景。比如第二个项目后台管理系统…你为什么要做这个后台管理系统呢?是为了解决什么问题。比如你管理一个商品列表的增加减少。需要一个背景吧。哦或者说你第一个电子书那个是c端的,你肯定需要一个管理系统吧,那就是第二个后台管理系统,但这两个难道不应该是一个项目吗?可以稍微包装一下,最起码让人看着不是玩具项目。个人观点。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务