Enforce consistent style

This commit is contained in:
Anthony Wang 2020-08-22 09:51:51 -05:00
parent 4f1ef57c5c
commit 8ee9dec723
No known key found for this signature in database
GPG Key ID: DCDAC3EF330BB9AC

View File

@ -1,30 +1,30 @@
int kmp(string &S, string &T) {
int kmp(string & S, string & T) {
// Generate KMP table
vector<int> F(T.length() + 1, 0);
vector<int> F(T.size()+1, 0);
F[0] = -1;
for (int i = 0; i < T.length(); i++) {
F[i + 1] = F[i];
while (F[i + 1] > -1 && T[i] != T[F[i + 1]]) F[i + 1] = F[F[i + 1]];
F[i + 1]++;
for (int i = 0; i < T.size(); ++i) {
F[i+1] = F[i];
while (F[i+1] > -1 && T[i] != T[F[i+1]]) F[i+1] = F[F[i+1]];
++F[i+1];
}
// Search
int i = 0, j = 0;
while (i < S.length()) {
while (i < S.size()) {
if (S[i] == T[j]) {
i++, j++;
if (j == T.length()) return i - j; // Found match
++i, ++j;
if (j == T.size()) return i - j; // Found match
/*if (j == T.size()) {
ret++; // Count matches
++ret; // Count matches
j = F[j];
if (j < 0) i++, j++;
if (j < 0) ++i, ++j;
}*/
}
else {
j = F[j];
if (j < 0) i++, j++;
}
if (j < 0) ++i, ++j;
}
}
return -1; // Match not found
}
}