VelizarAvramov

09. Longer Line

Nov 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09._Longer_Line
  4. {
  5.     class LongerLine
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double x1 = double.Parse(Console.ReadLine());
  10.             double y1 = double.Parse(Console.ReadLine());
  11.             double x2 = double.Parse(Console.ReadLine());
  12.             double y2 = double.Parse(Console.ReadLine());
  13.             double x3 = double.Parse(Console.ReadLine());
  14.             double y3 = double.Parse(Console.ReadLine());
  15.             double x4 = double.Parse(Console.ReadLine());
  16.             double y4 = double.Parse(Console.ReadLine());
  17.  
  18.             PrintLongerLine(x1, y1, x2, y2, x3, y3, x4, y4);
  19.  
  20.         }
  21.  
  22.         private static void PrintLongerLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  23.         {
  24.             double line1 = CalculatePythagorean(Math.Pow(x2 - x1, 2), Math.Pow(y2 - y1, 2));
  25.             double line2 = CalculatePythagorean(Math.Pow(x4 - x3, 2), Math.Pow(y4 - y3, 2));
  26.  
  27.             if (line1 >= line2)
  28.             {
  29.                 PrintClosesPoint(x1, y1, x2, y2);
  30.             }
  31.             else
  32.             {
  33.                 PrintClosesPoint(x3, y3, x4, y4);
  34.             }
  35.         }
  36.  
  37.         private static void PrintClosesPoint(double x1, double y1, double x2, double y2)
  38.         {
  39.             double line1 = CalculatePythagorean(x1, y1);
  40.             double line2 = CalculatePythagorean(x2, y2);
  41.  
  42.             if (line1 > line2)
  43.             {
  44.                 Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  45.             }
  46.             else
  47.             {
  48.                 Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  49.             }
  50.         }
  51.  
  52.         private static double CalculatePythagorean(double x, double y)
  53.         {
  54.             double result = Math.Sqrt(x * x + y * y);
  55.             return result;
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment