Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp37
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Unesi n:");
- int n = Convert.ToInt32(Console.ReadLine());
- List<string> adrese = new List<string>();
- List<int> x = new List<int>();
- List<int> y = new List<int>();
- Console.WriteLine("Unesi adrese i koordinate:");
- for (int i = 0; i < n * 2; i++)
- {
- if (i % 2 == 0)
- {
- adrese.Add(Console.ReadLine().Trim());
- }
- else
- {
- string str = Console.ReadLine();
- x.Add(Convert.ToInt32(str.Substring(0, str.IndexOf(" "))));
- y.Add(Convert.ToInt32(str.Substring(str.IndexOf(" "))));
- }
- }
- Dictionary<string, List<double>> lokacije = new Dictionary<string, List<double>>();
- for (int i = 0; i < n; i++)
- {
- lokacije.Add(adrese[i], new List<double>());
- for (int j = 0; j < n; j++)
- {
- lokacije[adrese[i]].Add(Math.Round(Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2)), 2));
- }
- }
- var prosek = lokacije.ToDictionary(s => s.Key, s => s.Value.Average()).OrderBy(s => s.Value).Select(z => z.Key).ToList();
- foreach(var p in prosek.Take(3))
- {
- Console.WriteLine(p);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement