# include
using namespace std;
Int next [1000];
Int KMP (string s1, string s2) {
Int I=0, j=0;
While (i
++i;
+ + j;
}
The else j=next [j];
}
If (j>=(int) s2. The length ())
Return I - s2. The length ();
The else return - 1;
}
Void getnext (string s) {
Int j=0, k=1;
Next [0]=1;
While (j<(int) s.l ength ()) {
If (k==1 | | s.s ubstr (j, 1)==s.s ubstr (k, 1)) {
+ + j;
+ + k;
Next [j]=k;
}
The else k=next [k].
}
}
Int main () {
Int t, I, j;
cin> t;
String s [1000] [10].
for(i=0; i
cin> S [I] [j];
for(i=0; i
S [I] [1]. Append (s [I] [1]. The substr (j, 1));
}
for(i=0; i
for(i=0; i
cout<1 & lt;
return 0;
}
CodePudding user response:
Photo is not clear, can't see requirementsHowever, getnext (s [I] [1]). If the length of the s [I] [1] greater than 1000 (s are append before [I] [1], the length of the really can't say for certain), the next [j]=k; The next array could cross
CodePudding user response: