反转字符串,但其指定的字串不反转nim
作者:
beasu | 来源:发表于
2019-10-20 17:10 被阅读0次
反转字符串,但其指定的字串不反转
import stacks
proc revstr(src,token:string):string =
var
s = Stack[char]()
i = 0
sl = src.len
tl = token.len
while i < sl :
if i <= sl - tl:
if src[i..<(i+tl)] == token:
for ti in countdown(tl - 1,0 ):
s.push(token[ti])
i += tl
else:
s.push(src[i])
i.inc
else:
s.push(src[i])
i.inc
while not s.empty:
result.add(s.pop)
return result
const
src = "Welcome you, my friend you"
token = "you"
echo revstr(src,token)
本文标题:反转字符串,但其指定的字串不反转nim
本文链接:https://www.haomeiwen.com/subject/skdamctx.html
网友评论