Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. def check_route_and_find_problem(route):
  2. n = len(route)
  3. max = 2147483647 # INT_MAX
  4. min = -2147483648 # INT_MIN
  5. flag = True
  6.  
  7. for i in range(1, n):
  8. booleans = [route[i] > route[i - 1], route[i] > min, route[i] < max, route[i] < route[i - 1], route[i] > min,
  9. route[i] < max]
  10. if (route[i] > route[i - 1] and
  11. route[i] > min and route[i] < max):
  12. min = route[i - 1]
  13. elif (route[i] < route[i - 1] and
  14. route[i] > min and route[i] < max):
  15. max = route[i - 1]
  16. else:
  17. flag = False
  18. break
  19. if flag:
  20. print("BST je validny")
  21. else:
  22. print("Neexistujte BST s takouto cestou")
  23. return i, min, max, route[i], booleans
  24.  
  25.  
  26. file = open('vstup.txt', 'r')
  27. filecontent = file.read().splitlines()
  28. file.close()
  29.  
  30. route = []
  31. for line in filecontent:
  32. route.append(int(line))
  33.  
  34. index, min, max, value, booleans = check_route_and_find_problem(route)
  35.  
  36. print(check_route_and_find_problem(route))
  37.  
  38. print(booleans)
  39. print('problemovy index', index - 1)
  40. print('hodnota na tomto indexe', route[index - 1])
  41. print('hodnota na o jedno mensom indexe', route[index - 2])
  42. print('hodnota na o jedno vacsom indexe', route[index])
  43. print('min', min)
  44. print('max', max)
  45.  
  46. # 631102 je prvy invalidny vstup, vsetko vyssie zbieha, pretoze min, max interval mi ostane v rozumnych medziach
  47. route[index - 1] = 631104
  48. print(check_route_and_find_problem(route))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement