Advertisement
Zneeky

Double X problem

Nov 22nd, 2021 (edited)
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Text;
  5.  
  6.  
  7.  
  8. namespace N_redica
  9.  
  10. {
  11.  
  12.     class Program
  13.  
  14.     {
  15.  
  16.  
  17. /**
  18.  * Auto-generated code below aims at helping you parse
  19.  * the standard input according to the problem statement.
  20.  **/
  21.  
  22.  
  23.  
  24.         static void Main(string[] args)
  25.         {
  26.             string LON1 = Console.ReadLine();
  27.             string LAT1 = Console.ReadLine();
  28.             string LON = LON1.Replace(',', '.');
  29.             string LAT = LAT1.Replace(',', '.');
  30.             NumberFormatInfo provider = new NumberFormatInfo();
  31.             provider.NumberDecimalSeparator = ".";
  32.             provider.NumberGroupSeparator = ",";
  33.             double longtitudeA = Convert.ToDouble(LON,provider);
  34.             double latitudeA = Convert.ToDouble(LAT,provider);
  35.           //  Console.WriteLine(longtitudeA);
  36.             int N = int.Parse(Console.ReadLine());
  37.             Dictionary<string, double> defib = new Dictionary<string, double>();
  38.             for (int i = 0; i < N; i++)
  39.             {
  40.                 string DEFIB = Console.ReadLine();
  41.                 string[] input = DEFIB.Split(";");
  42.  
  43.                 string name = input[1];
  44.                 string longt = input[input.Length - 2];
  45.                  LON = longt.Replace(',', '.');
  46.                 double longtitudeB = Convert.ToDouble(LON, provider);
  47.  
  48.                 string lat = input[input.Length - 1];
  49.                  LAT = lat.Replace(',', '.');
  50.                 double latitudeB = Convert.ToDouble(LAT, provider);
  51.  
  52.                 double x1 = longtitudeB - 0.00000000000000000000000000001 - longtitudeA;
  53.               //  Console.WriteLine(x1);
  54.                 double x=x1* Math.Cos((latitudeA - latitudeB) / 2);
  55.                 double y = latitudeB - latitudeA;
  56.                // Console.WriteLine(y);
  57.                 double distance = Math.Sqrt(x*x + y*y) * 6371.0;
  58.                 defib[name] = distance;
  59.  
  60.             }
  61.  
  62.             double shortestDistance = double.MaxValue;
  63.             string closestName = "";
  64.  
  65.             foreach (KeyValuePair<string, double> pair in defib)
  66.             {
  67.  
  68.                 if (pair.Value < shortestDistance)
  69.                 {
  70.                     shortestDistance = pair.Value;
  71.                     closestName = pair.Key;
  72.                 }
  73.             }
  74.  
  75.  
  76.  
  77.             Console.WriteLine(closestName);
  78.             Console.ReadLine();
  79.         }
  80.     }
  81. }
  82. /*input
  83. 3,879483
  84. 43,608177
  85. 3
  86. 1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;;3,87952263361082;43,6071285339217
  87. 2;Hotel de Ville;1 place Georges Freche 34267 Montpellier;;3,89652239197876;43,5987299452849
  88. 3;Zoo de Lunaret;50 avenue Agropolis 34090 Mtp;;3,87388031141133;43,6395872778854
  89.  
  90. output
  91. Maison de la Prevention Sante
  92. */
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement