Advertisement
Guest User

ex1.py

a guest
Oct 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. string = "aaaaa"
  2. substring = "aa"
  3.  
  4. total = 0
  5.  
  6. i = 0
  7. j = 0
  8.  
  9. oldIndex = 0
  10. # len(string) -> string.length
  11. while i < len(string):
  12.     # string[i] -> string.charAt(i)
  13.     if string[i] == substring[j]:
  14.         if j == 0:
  15.             oldIndex = i
  16.  
  17.         if j == len(substring) - 1:
  18.             total = total + 1
  19.             j = 0
  20.             i = oldIndex
  21.         else:
  22.             j = j + 1
  23.     elif j != 0:
  24.         i = oldIndex
  25.         j = 0
  26.  
  27.     i = i + 1
  28.  
  29. print total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement