Advertisement
Pietras286

Sort 1

Dec 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. namespace Problem15
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             int t = int.Parse(Console.ReadLine());
  8.             for (int i = 0; i < t; i++)
  9.             {
  10.                 int n = int.Parse(Console.ReadLine());
  11.                 List<Punkt> list = new List<Punkt>();
  12.                 for (int j = 0; j < n; j++)
  13.                 {
  14.                     string[] tab = Console.ReadLine().Split(' ');
  15.                     Punkt punkt = new Punkt(tab[0], int.Parse(tab[1]), int.Parse(tab[2]));
  16.                     list.Add(punkt);
  17.                 }
  18.                 list.Sort();
  19.                 foreach (Punkt item in list)
  20.                 {
  21.                     Console.WriteLine("{0} {1} {2}", item.Nazwa, item.X, item.Y);
  22.                 }
  23.                 Console.ReadLine();
  24.             }
  25.         }
  26.  
  27.         public class Punkt : IComparable<Punkt>
  28.         {
  29.             public string Nazwa { get; }
  30.             public int X { get; }
  31.             public int Y { get; }
  32.             public double Odleglosc { get; set; }
  33.             public Punkt(string nazwa, int x, int y)
  34.             {
  35.                 Nazwa = nazwa;
  36.                 X = x;
  37.                 Y = y;
  38.                 Odleglosc = Math.Sqrt(x * x + y * y);
  39.             }
  40.  
  41.             public int CompareTo(Punkt other)
  42.             {
  43.                 return Odleglosc.CompareTo(other.Odleglosc);
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement