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

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

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

#include <iomanip>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;


int main() {

        string str,s2;
        cin>>str>>s2;
        int count=0;
        int len=s2.size();
        for(int i=0;i<str.size();i++){
               string s1=str.substr(i,len);
               if(s1==s2) count++;
        }
        cout<<count;
        return 0;
}




全部评论

相关推荐

06-27 12:30
延安大学 C++
实习+外包,这两个公司底层融为一体了,如何评价呢?
一表renzha:之前面了一家外包的大模型,基本上都能答出来,那面试官感觉还没我懂,然后把我挂了,我都还没嫌弃他是外包,他把我挂了……
第一份工作能做外包吗?
点赞 评论 收藏
分享
炫哥_:哥们项目描述里面vector和mysql之类的都要写吗,直接开头技术栈巴拉巴拉就行了,完全不是技术点啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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