Example #1
0
func main() {
	var s, p string
	//s := "acabaabaabcacaabc"
	//p := "abaabcac"
	//s := "aabacaabaabaadaabaaeaa"
	//p := "aabaa"
	//s := "ababaaca"
	//p := "baac"
	//s := "bdbcbabcbab"
	//p := "bdbcba"
	for {
		_, err := fmt.Scan(&s, &p)
		if err != nil {
			if err == io.EOF {
				break
			} else {
				log.Fatal(err)
			}
		}
		next := make([]int, len(p)+1)
		next = kmp.Get_next(p)
		fmt.Printf("The matching postion  : %v\n", kmp.Kmp(s, p, next))
	}

}
func AmeicableString(s string, p string) int {
	var res []int
	next := make([]int, len(p))
	next = kmp.Get_next(p)
	if len(s) < len(p) {
		return 0
	}
	for i := 0; i < len(s); i++ {
		res = kmp.Kmp(s[i:]+s[:i], p, next)
		if len(res) != 0 {
			return 1
		}
	}
	return 0
}
Example #3
0
func main() {
	var n, m, j int
	fmt.Scan(&n)
	for ; n > 0; n-- {
		fmt.Scan(&m)
		for i := 0; i < m; i++ {
			fmt.Scan(&str[i])
		}
		answer = ""
		flag := 0
		sLen := len(str[0])
		for pLen := sLen; pLen >= 3; pLen-- {
			for i := 0; i <= sLen-pLen; i++ {
				patern = ""
				for j = i; j < i+pLen; j++ {
					patern += string(str[0][j])
				}
				for j = 1; j < m; j++ {
					next := make([]int, len(patern)+1)
					next = kmp.Get_next(patern)
					if kmp.Kmp(str[j], patern, next) == -1 {
						break
					}
				}
				if j == m {
					flag = 1
					if len(answer) == len(patern) && answer > patern {
						answer = patern
					}
					if len(answer) < len(patern) {
						answer = patern
					}
				}
			}
			if flag == 1 {
				break
			}
		}
		if answer == "" {
			fmt.Println("no significant commonalities")
		} else {
			fmt.Println(answer)
		}
	}
}