fork download
  1. '''
  2. Coordonatele a N puncte in planul cartezian sunt
  3. memorate in doi vectori:
  4. A - vectorul absciselor
  5. O - vectorul ordonatelor
  6. Output: Sa se determine in plan segmentul de lungime maxima.
  7. De precizat ca se cere o singura solutie, daca sunt mai multe
  8. segmente de lungime maxima.
  9.  
  10. Example:
  11. Introduceti numarul de puncte -> 3
  12. Introduceti coordonatele punctelor ->
  13. Abscisa punctului 0 -> 1
  14. Ordonata punctului 0 -> 3
  15. Abscisa punctului 1 -> -1
  16. Ordonata punctului 1 -> 1
  17. Abscisa punctului 2 -> 2
  18. Ordonata punctului 2 -> -4
  19. Max Segment -> 7.07107
  20. Points -> (1, 3) - (2, -4)
  21. '''
  22.  
  23. import math
  24.  
  25. def main():
  26. Abs = [0] * 100
  27. Ord = [0] * 100
  28. maxA = 0
  29. maxB = 0
  30. dist = 0
  31. N = int(input("Number of points -> "))
  32. for i in range(0, N):
  33. Abs[i] = int(input(f"Abscisa point {i} = "))
  34. Ord[i] = int(input(f"Ordonata point {i} = "))
  35. for i in range(0, N - 1):
  36. for j in range(i + 1, N):
  37. d = math.sqrt((Abs[i] - Abs[j]) * (Abs[i] - Abs[j]) + (Ord[i] - Ord[j]) * (Ord[i] - Ord[j]))
  38. if d > dist:
  39. dist = d
  40. maxA = i
  41. maxB = j
  42. print(f"Largest Segment is { dist } with points: ({Abs[maxA]},{Ord[maxA]}) - ({Abs[maxB]},{Ord[maxB]})")
  43.  
  44. main()
  45.  
Success #stdin #stdout 0.02s 9356KB
stdin
3
1 
3
-1
1
2
-4
stdout
Number of points -> Abscisa point 0 = Ordonata point 0 = Abscisa point 1 = Ordonata point 1 = Abscisa point 2 = Ordonata point 2 = Largest Segment is 7.0710678118654755 with points: (1,3) - (2,-4)