aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-08-22 09:51:51 -0500
committerAnthony Wang2020-08-22 09:51:51 -0500
commit8ee9dec7237079dd70bb59198bad7b83a14adf00 (patch)
treeb7a28dfd3c1c9251496fc4cbffddfa4f1a9b69d6
parent4f1ef57c5c5fcb959adc8af422394ef4d8527b28 (diff)
Enforce consistent style
-rw-r--r--String/kmp.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/String/kmp.cpp b/String/kmp.cpp
index ebb50ad..49341c3 100644
--- a/String/kmp.cpp
+++ b/String/kmp.cpp
@@ -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
-} \ No newline at end of file
+}