我发现我输入的时候,最多只能输入4094个字符。我尝试了很多方法比如把string换为char数组,把输入方法改成scanf和fgets,都没用
code
#include<iostream>
#include<cstring>
using namespace std;
int main(){
string lstr,sstr;
cin>>lstr>>sstr;
int llen=(unsigned int)lstr.size();
int slen=(unsigned int)sstr.size();
bool y;
int next[slen]={0};
for(int i=1;i<slen;i++){
if(sstr[i]==sstr[next[i-1]]){
next[i]=next[i-1]+1;
}else if(sstr[i]==sstr[0]){
next[i]=1;
}else{
next[i]=0;
}
}
int i=0,j=0;
while(i<llen){
if(j==slen)cout<<i-j+1<<endl;
if(lstr[i]==sstr[j]){
i++;
j++;
}else if(j>0){
j=next[j-1];
}else{
i++;
j=0;
}
}
if(j==slen)cout<<i-j+1<<endl;
for(i=0;i<slen;i++)cout<<next[i]<<' ';
return 0;
}