-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdefibrillators.cs
More file actions
41 lines (36 loc) · 1.26 KB
/
defibrillators.cs
File metadata and controls
41 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
public class Program
{
public static double hypo(double x, double y)
{
return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
}
public static double ToRadians(string angleInDegrees)
{
return Convert.ToDouble(angleInDegrees.Replace(",", ".")) * Math.PI / 180;
}
public static void Main()
{
double minDistance = double.PositiveInfinity;
string closestDefibName = "";
double longitude = ToRadians(Console.ReadLine());
double latitude = ToRadians(Console.ReadLine());
int nbDefib = int.Parse(Console.ReadLine());
for (int i = 0; i < nbDefib; i++)
{
string[] defib = Console.ReadLine().Split(';');
double defibLongitude = ToRadians(defib[4]);
double defibLatitude = ToRadians(defib[5]);
double x = (defibLongitude - longitude) * Math.Cos((latitude + defibLatitude) / 2);
double y = defibLatitude - latitude;
int EARTH_RADIUS = 6371;
double distance = hypo(x, y) * EARTH_RADIUS;
if (distance < minDistance)
{
minDistance = distance;
closestDefibName = defib[1];
}
}
Console.WriteLine(closestDefibName);
}
}