Advertisement
Pavle_nis

Untitled

Mar 2nd, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.55 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> lista = new List<string>();
  36.             List<string> lista1 = new List<string>();
  37.  
  38.             /*for (int i = 0; i < n; i++)
  39.             {
  40.               for (int j = i + 1; j < n; j++)
  41.               {
  42.                 lista.Add(adrese[i] + " " + adrese[j]);
  43.               }
  44.             }*/
  45.  
  46.             for (int j = 0; j < n; j++)
  47.             {
  48.                 for (int k = j + 1; k < n; k++)
  49.                 {
  50.                     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)));
  51.                 }
  52.             }
  53.  
  54.             string pom = "";
  55.             for (int i = 0; i < lista1.Count - 1; i++)
  56.             {
  57.                 for (int j = i + 1; j < lista1.Count; j++)
  58.                 {
  59.                     if (Convert.ToDouble(lista1[i].Substring(lista1[i].IndexOf("/") + 1)) > Convert.ToDouble(lista1[j].Substring(lista1[j].IndexOf("/") + 1)))
  60.                     {
  61.                         /*pom = lista1[i].Substring(lista1[i].IndexOf("/") + 1);
  62.                         lista1[i] = lista1[i].Replace(lista1[i].Substring(lista1[i].IndexOf("/") + 1), lista1[j].Substring(lista1[j].IndexOf("/") + 1));
  63.                         lista1[j] = lista1[j].Replace(lista1[j].Substring(lista1[j].IndexOf("/") + 1), pom);*/
  64.                         pom = lista1[i];
  65.                         lista1[i] = lista1[j];
  66.                         lista1[j] = pom;
  67.                     }
  68.                 }
  69.             }
  70.  
  71.             List<string> lista2 = new List<string>();
  72.  
  73.             for (int i = 0; i < lista1.Count; i++)
  74.             {
  75.                 for (int j = i + 1; j < lista1.Count; j++)
  76.                 {
  77.                     if ((lista1[i].Contains(lista1[j].Substring(0, lista1[j].IndexOf("-")))
  78.                         || lista1[i].Contains(lista1[j].Substring(lista1[j].IndexOf("-") + 1, lista1[j].IndexOf("/") - (lista1[j].IndexOf("-") + 1)))) && lista2.Count < 4)
  79.                     {
  80.                         lista2.Add(lista1[i].Substring(0, lista1[i].IndexOf("-")));
  81.                         lista2.Add(lista1[j].Substring(lista1[j].IndexOf("-") + 1, lista1[j].IndexOf("/") - (lista1[j].IndexOf("-") + 1)));
  82.                         break;
  83.                     }
  84.                     else
  85.                     {
  86.                         break;
  87.                     }
  88.                 }
  89.             }
  90.             //lista1.Sort();
  91.             lista2 = lista2.Distinct().ToList();
  92.  
  93.             /*for (int i = 0; i < 2; i++)
  94.             {
  95.                 lista2.Add(lista1[i].Substring(0, lista1[i].IndexOf("-")));
  96.                 lista2.Add(lista1[i].Substring(lista1[i].IndexOf("-"), lista1[i].IndexOf("/") - lista1[i].IndexOf("-")));
  97.             }*/
  98.  
  99.             /*foreach (var x1 in lista1.Take(2))
  100.             {
  101.                 lista2.Add(x1.Substring(0, x1.IndexOf("-")));
  102.                 lista2.Add(x1.Substring(x1.IndexOf("-") + 1, x1.IndexOf("/") - (x1.IndexOf("-") + 1)));
  103.             }
  104.             lista2 = lista2.Distinct().ToList();*/
  105.  
  106.             foreach (var x1 in lista2)
  107.             {
  108.                 Console.WriteLine(x1);
  109.             }
  110.             /*string adrese1 = "";
  111.             for(int i = 0; i < 2; i++)
  112.             {
  113.                 if(!lista1[i].Contains(lista1[i + 1]))
  114.                 {
  115.                     adrese1 += lista1[i].Substring(0, lista1[i].IndexOf("-")) + "\n" + lista1[i].Substring(lista1[i].IndexOf("-"), lista1[i].IndexOf("/") - lista1[i].IndexOf("-"));
  116.                 }
  117.             }*/
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement