Advertisement
Guest User

Untitled

a guest
Feb 26th, 2021
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const LON = +readline().replace(",", ".");
  2. const LAT = +readline().replace(",", ".");
  3. const N = parseInt(readline());
  4. const defibNames = []
  5. const allDistances = []
  6.  
  7. for (let i = 0; i < N; i++) {
  8. const DEFIB = readline();
  9. const data = DEFIB.split(";")
  10. defibNames.push(data[1])
  11.  
  12. const defibLON = +data[data.length - 1].replace(",", ".")
  13. const defibLAT = +data[data.length - 2].replace(",", ".")
  14.  
  15. const x = (LON - defibLON) * (Math.cos(defibLAT + LAT) / 2)
  16. const y = (LAT - defibLAT)
  17. const d = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) * 6371
  18.  
  19. allDistances.push(d)
  20. }
  21.  
  22. console.log(defibNames[allDistances.indexOf(Math.min(...allDistances))]);
  23.  
  24. // Write an answer using console.log()
  25. // To debug: console.error('Debug messages...');
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement