最后三个wa了呜呜呜,大佬捞捞
查看原帖
最后三个wa了呜呜呜,大佬捞捞
394076
BLbl2001b楼主2021/11/11 01:03
#include<iostream>
using namespace std;
const int N = 1e6 + 10;
char s1[N],s2[N];
int ne[N];
int temp;
int main(){
	cin>>s1+1>>s2+1;
	for(int i = 2,j = 0;s2[i] != '\0';i++){
		while(j && s2[i] != s2[j+1]){
			j = ne[j];	
		}
		if(s2[i] == s2[j+1]){
			j++;
		}
		
		ne[i] = j;
	}
	for(int i = 1,j = 0;s1[i] != '\0';i++){
		
		while(j && s1[i] != s2[j+1]){
			j = ne[j];
		}
		if(s1[i] == s2[j+1]){
			j++;
		}
		if(s2[j+1] == '\0'){
			cout<<i-j+1<<endl;
			temp = j;
			j = 0;
		}	
	}
	for(int k = 1;k <= temp;k++){
			cout<<ne[k]<<" ";
		}
	return 0; 
	 
}
2021/11/11 01:03
加载中...