-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefibrillator.cs
More file actions
60 lines (51 loc) · 1.7 KB
/
Copy pathDefibrillator.cs
File metadata and controls
60 lines (51 loc) · 1.7 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string LON = Console.ReadLine().Replace(',', '.');
string LAT = Console.ReadLine().Replace(',', '.');
double lon = double.Parse(LON);
double lat = double.Parse(LAT);
int N = int.Parse(Console.ReadLine());
string closest = "";
double minDist = double.MaxValue;
for (int i = 0; i < N; i++)
{
string DEFIB = Console.ReadLine();
double lon2 = getLon(DEFIB);
double lat2 = getLat(DEFIB);
if (dist(lon, lat, lon2, lat2) < minDist)
{
minDist = dist(lon, lat, lon2, lat2);
closest = getName(DEFIB);
}
}
Console.WriteLine(closest);
}
static double dist(double lonA, double latA, double lonB, double latB)
{
return (double)Math.Sqrt((double)Math.Pow((lonB - lonA)
* (double)Math.Cos((latA + latB) / 2.0D), 2)
+ (double)Math.Pow(latB - latA, 2)) * 6371.0D;
}
static string getName(string s)
{
return s.Split(';')[1];
}
static double getLon(string s)
{
return double.Parse(s.Split(';')[4].Replace(',', '.'));
}
static double getLat(string s)
{
return double.Parse(s.Split(';')[5].Replace(',', '.'));
}
}
}