use kmp to solve some practical problems