throw brick to attract jade

My solution to Jamesxu's problem.

string[ ] p = {"aaabbb", "aaab", "ab}
int [ ] pos = {0,0,0}

loop through target string
loop through number of patterns (n)
s += call match(pos, n, target char, pattern)
if s is 0 then break
end loop
return s

match function
if pos is -1 then return 0
else if target char equals to pattern char at position pos
then increase pos by 1 (don't forget mod here)
return n
else set pos to -1 and return 0

所有跟帖: 

回复:throw brick to attract jade -tank- 给 tank 发送悄悄话 (2765 bytes) () 02/13/2008 postreply 13:26:08

回复:回复:you don't need to loop string three times! -sub101- 给 sub101 发送悄悄话 (0 bytes) () 02/13/2008 postreply 13:30:15

i never loop the string 3 times. -tank- 给 tank 发送悄悄话 (64 bytes) () 02/13/2008 postreply 13:31:33

回复:You are right. However, I have one more question, -sub101- 给 sub101 发送悄悄话 (19 bytes) () 02/13/2008 postreply 13:58:42

回复:回复:You are right. However, I have one more question, -tank- 给 tank 发送悄悄话 (207 bytes) () 02/13/2008 postreply 14:10:10

回复:回复:回复:I suck at algorithms. I discussed them -sub101- 给 sub101 发送悄悄话 (34 bytes) () 02/13/2008 postreply 14:13:59

the fastest solution should be using DFA -Jamesxu- 给 Jamesxu 发送悄悄话 (36 bytes) () 02/13/2008 postreply 17:30:31

回复:thanks! -sub101- 给 sub101 发送悄悄话 (0 bytes) () 02/13/2008 postreply 20:23:01

请您先登陆,再发跟帖!