throw brick to attract jade

来源: 2008-02-13 12:21:26 [旧帖] [给我悄悄话] 本文已被阅读:

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