Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # -*- encoding: utf-8 -*-
  2. import sys
  3.  
  4. class Gato(object):
  5.  
  6. def __init__(self, x, y):
  7. self.x = x
  8. self.y = y
  9.  
  10. def addPasso(self):
  11. self.y += 1
  12.  
  13. def isColidiu(self, x, y):
  14. if self.x == x and self.y== y:
  15. return True
  16. return False
  17.  
  18. def __repr__(self):
  19. return 'X:{} Y:{}'.format(self.x, self.y)
  20.  
  21.  
  22. class Carro(object):
  23.  
  24. def __init__(self, x, y, v):
  25. self.x = x
  26. self.y = y
  27. self.v = v
  28. self.newCar = 0
  29.  
  30. def addPasso(self):
  31. self.x += self.v
  32.  
  33. def onMedium(self):
  34. if self.x > 6 and self.newCar == 0:
  35. self.newCar += 1
  36. return True
  37. return False
  38.  
  39. def onEnd(self):
  40. if self.x >= 12:
  41. return True
  42. return False
  43.  
  44. def __repr__(self):
  45. return 'X:{} Y:{} V:{}'.format(self.x, self.y, self.v)
  46.  
  47.  
  48. line = sys.stdin.readline.split()
  49. entradas = [int(l) for l in line]
  50. cars = [Carro(0, y+1, v) for y, v in enumerate(entradas)]
  51. cat = Gato(6,0)
  52. colisao = 0
  53.  
  54. for x in xrange(0, 6):
  55. if colisao != 0:
  56. break
  57. else:
  58. cat.addPasso()
  59. for car in cars:
  60. car.addPasso()
  61. if cat.isColidiu(car.x, car.y):
  62. colisao = cat.y
  63. break
  64. else:
  65. if car.onMedium():
  66. cars.append(Carro(0, car.y, car.v))
  67. if car.onEnd():
  68. cars.remove(car)
  69. print colisao
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement