fork download
  1. string = 'abcdcdc'
  2. sub_string = 'cdc'
  3.  
  4. idx = 0
  5. count_p = 0
  6. count = 0
  7. for i in list(string):
  8. if i in sub_string[idx]:
  9. count += 1
  10. idx += 1
  11. if idx == 2:
  12. idx = 0
  13. elif count == 3:
  14. count = 0 if i != 'c' else 1
  15. count_p += 1
  16.  
  17. else:
  18. count = 0
  19.  
  20.  
  21. print(count_p)
Success #stdin #stdout 0.02s 28376KB
stdin
Standard input is empty
stdout
2