D: NH字符串

给一个字符串 T,问在字符串 T 中可以包含最多多少个不重叠的字符串 S。
字符串中的每个字符为小写或者大写字母。

输入
第一行输入一个字符串 S。
第二行输入一个字符串 T。

输出
输出一行,包括一个整数表示答案。
样例输入 Copy
Aba
Abababa
样例输出 Copy
1
提示
50%的数据,1<=字符串T长度<=20000,1<=字符串S长度<=100
100%的数据,1<=字符串T长度<=1000000,1<=字符串S长度<=100000。其中多数是随机产生。
在这里插入图片描述

#include <bits/stdc++.h>
#define int long long
using namespace std;
string s,t;
int cnt,id;
signed main(){
    ios::sync_with_stdio(0);
    cin >> s >> t;
    int sl = s.size();
    for(int i = 0; i < t.size();i++){
        if(t[i] == s[id]) id++;
        else if(t[i] == s[0]) id = 1;
        else id = 0;
        if(id == sl){
            cnt++;
            id = 0;
        }
    }
    cout << cnt;
    return 0;
}

原文地址:https://www.cnblogs.com/xcfxcf/p/12301574.html