Guest User

Untitled

a guest
Nov 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. path = raw_input("Введіть шлях!")
  3.  
  4. x = 0
  5. y = 0
  6. l = 0
  7.  
  8. pt = []
  9. count = 0
  10. k = 0
  11.  
  12. class Position:
  13.  
  14. def __init__(self, x, y):
  15. self.x = x
  16. self.y = y
  17.  
  18. for p in path:
  19. a = x
  20. b = y
  21. if k == 0:
  22. c = str(p)
  23. if c == 'r':
  24. x = x + 1
  25. count = count + 1
  26. elif c == 'l':
  27. x = x - 1
  28. count = count + 1
  29. elif c == 'u':
  30. y = y + 1
  31. count = count + 1
  32. elif c == 'd':
  33. y = y - 1
  34. count = count + 1
  35. t = Position(x, y)
  36. pt.append(t)
  37. l = 0
  38. if pt:
  39. k = 1
  40. while l <= count - 1:
  41. ins = pt[l]
  42. l = l + 1
  43. if x == ins.x and y == ins.y:
  44. k = 1
  45. else:
  46. k = 0
  47. else:
  48. t = 1
  49.  
  50.  
  51.  
  52. if k == 1:
  53. print 'finish', count
Add Comment
Please, Sign In to add comment