Advertisement
Pavle_nis

Untitled

Mar 3rd, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 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 ConsoleApp36
  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.             List<string> lista1 = new List<string>();
  36.  
  37.             for (int j = 0; j < n; j++)
  38.             {
  39.                 for (int k = j + 1; k < n; k++)
  40.                 {
  41.                     lista1.Add(adrese[j] + "-" + adrese[k] + "/" + Convert.ToString(Math.Round(Math.Sqrt(Math.Pow(x[j] - x[k], 2) + Math.Pow(y[j] - y[k], 2)), 2)));
  42.                 }
  43.             }
  44.  
  45.             string pom = "";
  46.             for (int i = 0; i < lista1.Count - 1; i++)
  47.             {
  48.                 for (int j = i + 1; j < lista1.Count; j++)
  49.                 {
  50.                     if (Convert.ToDouble(lista1[i].Substring(lista1[i].IndexOf("/") + 1)) > Convert.ToDouble(lista1[j].Substring(lista1[j].IndexOf("/") + 1)))
  51.                     {
  52.                         pom = lista1[i];
  53.                         lista1[i] = lista1[j];
  54.                         lista1[j] = pom;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement