Merge pull request #1075 from flaviut/inlinedocs
Add some documentations and code examples in system
This commit is contained in:
commit
a690e7b267
71 changed files with 2521 additions and 15 deletions
35
tests/misc/tpos.nim
Normal file
35
tests/misc/tpos.nim
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
discard """
|
||||
file: "tpos.nim"
|
||||
output: "6"
|
||||
"""
|
||||
# test this particular function
|
||||
|
||||
proc mypos(sub, s: string, start: int = 0): int =
|
||||
var
|
||||
i, j, M, N: int
|
||||
M = sub.len
|
||||
N = s.len
|
||||
i = start
|
||||
j = 0
|
||||
if i >= N:
|
||||
result = -1
|
||||
else:
|
||||
while True:
|
||||
if s[i] == sub[j]:
|
||||
Inc(i)
|
||||
Inc(j)
|
||||
else:
|
||||
i = i - j + 1
|
||||
j = 0
|
||||
if (j >= M) or (i >= N): break
|
||||
if j >= M:
|
||||
result = i - M
|
||||
else:
|
||||
result = -1
|
||||
|
||||
var sub = "hello"
|
||||
var s = "world hello"
|
||||
write(stdout, mypos(sub, s))
|
||||
#OUT 6
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue