Language: C++

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

int next[1000010];
string str;
string s;

void getnext1()
{
 
    int i,n,k;
    n=s.length();
    k=-1;
    next[0]=-1;
    i=0;
    while(i<n)
    {
        if(k==-1 || s[i]==s[k])// k=-1用于指针i的移动 结合k=next[k]看
        {
            i++;
            k++;
            next[i]=k;
        }
        else k=next[k];
    }
}
 
int kmp(int x)//匹配ab两串，a为父串
{
    int i=x,j=0;
    int len1=str.length();
    int len2=s.length();
    while(i<len1&&j<len2)
    {
      if(j==-1||str[i]==s[j])
        ++i,++j;
      else
        j=next[j];
//ABCDABTABCDABC
//ABCDABC
    }
    if(j==len2)
    return  i-j;
    else
        return -1;
}

int main()
{
	cin >> str >> s;
	int len1=str.length();
	string strr = str;
    int len2=s.length();
    if(len1>len2){
    	str = str+strr;
	}
	else{
		int cishu;
	    if(len2%len1==0){
	    	cishu = len2/len1-1;
		}
		else{
			cishu = len2/len1;
		}
	    for(int i = 0; i < cishu;i++){
	    	str = str+strr;
		}
	}
	len1=str.length();
	getnext1();
	//cout << str << endl;
	int lll = kmp(0);
	if(lll==-1){
		printf("0\n");
	}
	else{
		int maxx = 0;
		int temp = 0;
		
		int j = lll;
		int ii = 0;
		bool flag = false;
		//cout << str<< endl;
		while(j<len1){
			if(s[ii]!=str[j]){		
				flag = true;
				maxx = max(temp, maxx);
				temp = 0;
				ii = 0;
				lll = kmp(j);
				j++;
				//cout << 111 << endl;
			}
			else{
				ii++;
				if(ii==len2){
					ii = 0;
					temp++;
					
				}
				
				j++;
			} 
			
		}
		//cout << flag << endl;
		if(!flag) printf("-1\n");
		else{
			printf("%d\n", max(temp, maxx));
		}
	}
	//cout << kmp() << endl;
	return 0;
}


Compiler output:
a.cc: In function 'void getnext1()':
a.cc:16:5: error: reference to 'next' is ambiguous
   16 |     next[0]=-1;
      |     ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:5: note:                 'int next [1000010]'
    6 | int next[1000010];
      |     ^~~~
a.cc:24:13: error: reference to 'next' is ambiguous
   24 |             next[i]=k;
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:5: note:                 'int next [1000010]'
    6 | int next[1000010];
      |     ^~~~
a.cc:26:16: error: reference to 'next' is ambiguous
   26 |         else k=next[k];
      |                ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:5: note:                 'int next [1000010]'
    6 | int next[1000010];
      |     ^~~~
a.cc: In function 'int kmp(int)':
a.cc:40:11: error: reference to 'next' is ambiguous
   40 |         j=next[j];
      |           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:5: note:                 'int next [1000010]'
    6 | int next[1000010];
      |     ^~~~