Re: [问题] 请问这题有谁会呢?

楼主: SansWord (是妳)   2010-11-13 01:26:35
※ 引述《cedog (YA)》之铭言:
: insert(str1,str2,int):插入字串,将str2插入str1的位置int,从0开始。
: replace(str1,str2,int):取代字串,将str1位置int,开始取代成str2,int是从0开始。
insert(str1,str2,int):: String -> String -> Integer -> String
insert(str1, str2, 0)
= str2 ++ str1
insert(a::str1, str2, b)
= a::( insert(str1, str2, (b-1)) )
replace(str1, str2, int):: String -> String -> Integer -> String
replace(a::as, b::bs, 0)
= b::(replace (as, bs, 0)
replace( nil, s2, 0)
= nil
replace( s1, nil, 0)
= s1
replace( a::as, s2, b)
= a::( replace(as, s2, (b-1) ) )
这样应该是ok的吧?
这不是任何程式码,充其量就是有点functional 的pseudo code
希望能帮到你

Links booklink

Contact Us: admin [ a t ] ucptt.com