Advertisement
Pavle_nis

Untitled

Mar 4th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp37
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Unesi n:");
  14.             int n = Convert.ToInt32(Console.ReadLine());
  15.  
  16.             List<string> adrese = new List<string>();
  17.             List<int> x = new List<int>();
  18.             List<int> y = new List<int>();
  19.  
  20.             Console.WriteLine("Unesi adrese i koordinate:");
  21.             for (int i = 0; i < n * 2; i++)
  22.             {
  23.                 if (i % 2 == 0)
  24.                 {
  25.                     adrese.Add(Console.ReadLine().Trim());
  26.                 }
  27.                 else
  28.                 {
  29.                     string str = Console.ReadLine();
  30.                     x.Add(Convert.ToInt32(str.Substring(0, str.IndexOf(" "))));
  31.                     y.Add(Convert.ToInt32(str.Substring(str.IndexOf(" "))));
  32.                 }
  33.             }
  34.  
  35.             Dictionary<string, List<double>> lokacije = new Dictionary<string, List<double>>();
  36.  
  37.             for (int i = 0; i < n; i++)
  38.             {
  39.                 lokacije.Add(adrese[i], new List<double>());
  40.  
  41.                 for (int j = 0; j < n; j++)
  42.                 {
  43.                     lokacije[adrese[i]].Add(Math.Round(Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2)), 2));
  44.                 }
  45.             }
  46.  
  47.             var prosek = lokacije.ToDictionary(s => s.Key, s => s.Value.Average()).OrderBy(s => s.Value).Select(z => z.Key).ToList();
  48.  
  49.             foreach(var p in prosek.Take(3))
  50.             {
  51.                 Console.WriteLine(p);
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement