Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- cdn_x = input("Введіть координату x!")
- cdn_y = input("Введіть координату y!")
- path = raw_input("Введіть шлях!")
- x = cdn_x
- y = cdn_y
- l = 0
- pt = []
- count = 0
- k = 0
- class Position:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- t = Position(x, y)
- pt.append(t)
- for p in path:
- if k == 0:
- c = str(p)
- if c == 'r':
- x = x + 1
- count = count + 1
- elif c == 'l':
- x = x - 1
- count = count + 1
- elif c == 'u':
- y = y + 1
- count = count + 1
- elif c == 'd':
- y = y - 1
- count = count + 1
- l = 0
- if pt:
- k = 1
- while l <= count - 1:
- ins = pt[l]
- l = l + 1
- if x == ins.x and y == ins.y:
- k = 1
- else:
- k = 0
- t = Position(x, y)
- pt.append(t)
- if k == 1:
- print 'fail', count
- elif k == 0:
- print 'Success'
Add Comment
Please, Sign In to add comment