Guest User

Untitled

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