Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. for i in input:
  2. o = 0
  3. p = False
  4. a = i.split()
  5.  
  6. c = 0
  7. #start position
  8. x = 0
  9. y = 0
  10.  
  11. for j in i:
  12. if j != " ":
  13. if j == "R":
  14. x += 1
  15. if j == "L":
  16. x -= 1
  17. if j == "U":
  18. y += 1
  19. if j == "D":
  20. y -= 1
  21. o += 1
  22.  
  23. res = str(x) + " " + str(y)
  24.  
  25. if o == len(a):
  26. p = True
  27.  
  28. while p == True:
  29. a = res.split()
  30.  
  31. x = int(a[0])
  32. y = int(a[1])
  33. for k in range(o):
  34. if x != 0:
  35. if x > 0:
  36. x -= 1
  37. if x < 0:
  38. x += 1
  39. c += 1
  40. if y != 0:
  41. if y > 0:
  42. y -= 1
  43. if y < 0:
  44. y += 1
  45. c += 1
  46.  
  47. if p == False:
  48. break
  49.  
  50. if x == 0 and y == 0:
  51. print(c)
  52. p = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement