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

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

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

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

int main() {

    char str[100] = { 0 };
    char substr[100] = { 0 };

    cin.getline(str, sizeof(str));
    cin.getline(substr, sizeof(substr));

    int count = 0;

    // write your code here......
    string str1(str);
    string str2(substr);

    int i=0;
    while (str1.find(str2, i) != -1) {
        count++;
        i = str1.find(str2, i) + 1;
    }
    

    cout << count << endl;

    return 0;
}

c++学习 文章被收录于专栏

一起学习成长

全部评论

相关推荐

阿里巴巴各部门年终奖开奖了,有人拿到了220w
真烦好烦真烦:拿命换钱呢,公司给你220万,肯定是因为你对公司的贡献大于220万,想想要多厉害多累才能达到
投递阿里巴巴集团等公司10个岗位 >
点赞 评论 收藏
分享
如题,这操作。。。。
真烦好烦真烦:既想享受国家的招聘应届生福利,又不想培养新人,我只能说这种企业的ld太过分了
投递美的集团等公司10个岗位 >
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务