Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85fce78

Browse files
author
shengshijun
committed
字符串朴素匹配算法
1 parentba08647 commit85fce78

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎string/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
# -*- coding:UTF-8
3+
__author__='shenshijun'

‎string/simple.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding:UTF-8
3+
__author__='shenshijun'
4+
5+
6+
defmatch(origin,pattern):
7+
origin_index,pattern_index=0,0
8+
pattern_len=len(pattern)
9+
whileorigin_index<len(origin):
10+
forpattern_indexinxrange(pattern_len):
11+
ifpattern[pattern_index]!=origin[origin_index]:
12+
origin_index-= (pattern_index-1)
13+
break
14+
else:
15+
origin_index+=1
16+
pattern_index+=1
17+
18+
iforigin[origin_index]==pattern[pattern_index]:
19+
returnorigin_index-pattern_index
20+
21+
22+
defmain():
23+
printmatch("absbsbshdhhd",'sb')
24+
25+
26+
if__name__=="__main__":
27+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp