From 0f66072da7f5bb287400b09a343dd250631d7f09 Mon Sep 17 00:00:00 2001 From: uh-zz Date: Fri, 21 Oct 2022 21:08:53 +0900 Subject: [PATCH] refactor: fmt.Printf in strings/kmp --- strings/kmp/kmp.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/strings/kmp/kmp.go b/strings/kmp/kmp.go index a0f138724..b46d5484c 100644 --- a/strings/kmp/kmp.go +++ b/strings/kmp/kmp.go @@ -71,10 +71,11 @@ func Kmp(text string, word string) Result { m, i, c := 0, 0, 0 t := kmpTable(word) for m+i < len(text) { - fmt.Printf("\n comparing characters %c %c at positions %d %d", text[m+i], word[i], m+i, i) + message := fmt.Sprintf("\tcomparing characters %c %c at positions %d %d", text[m+i], word[i], m+i, i) + c++ if word[i] == text[m+i] { - fmt.Printf(" - match") + fmt.Printf("%s - match\n", message) if i == len(word)-1 { return Result{ m, c, @@ -82,6 +83,7 @@ func Kmp(text string, word string) Result { } i++ } else { + fmt.Printf("%s\n", message) m = m + i - t[i] if t[i] > -1 { i = t[i]