Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Código em python para busca de padrões
- #Otimizado para pesquisa onde os caracteres são diferentes
- def listaindice(t):
- cont = 0
- for i in t:
- t += " %s[%i]" %(i, cont)
- cont += 1
- return t
- def search(padrao, texto):
- M = len(padrao)
- N = len(texto)
- i = 0
- while i <= N-M:
- for j in range(M):
- if texto[i+j] != padrao[j]:
- break
- j = j + 1
- if j==M: # Quando o padrão for encontrado volta ao loop
- print("Padrao encontrado no indice:", i)
- i = i + M
- elif j==0:
- i = i + 1
- else:
- i = i + j
- texto = "abacate"
- padrao = "aba"
- print(listaindice(texto))
- search(padrao, texto)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement