From 4b4883cd58a34a0babf74cf990a2f47d18b7df64 Mon Sep 17 00:00:00 2001 From: Navidda Date: Wed, 16 Dec 2015 14:52:44 +0330 Subject: [PATCH] Update KMP.cpp --- KMP.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/KMP.cpp b/KMP.cpp index 666efc4..cb2bd67 100644 --- a/KMP.cpp +++ b/KMP.cpp @@ -4,6 +4,7 @@ const int M = 1000 * 100 + 4; int f[M]; string s,t; bool match[M]; +// it isn't needed to initialize match[] or f[] void kmp() { f[0] = -1; @@ -16,6 +17,7 @@ void kmp() for (int i = 0; i < SZ(s); i++) { while(pos != -1 && (pos == SZ(t) || s[i] != t[pos])) pos = f[pos]; pos ++; - if (pos == SZ(t)) match[i - pos + 1] = 1; + if (pos == SZ(t)) match[i] = 1; + else match[i] = 0; } }