anizko

03. Longer Line

Jul 3rd, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._Longer_Line
  4. {
  5.     class Program
  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.  
  14.             double x3 = double.Parse(Console.ReadLine());
  15.             double y3 = double.Parse(Console.ReadLine());
  16.             double x4 = double.Parse(Console.ReadLine());
  17.             double y4 = double.Parse(Console.ReadLine());
  18.  
  19.             CheckAndPrintDistance(x1, y1, x2, y2, x3, y3, x4, y4);
  20.         }
  21.  
  22.         static double Distance(double x, double y)
  23.         {
  24.             double distance = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
  25.             return distance;
  26.         }
  27.  
  28.         static void CheckAndPrintDistance (double x1, double y1, double x2, double y2,
  29.             double x3, double y3, double x4, double y4)
  30.  
  31.         {
  32.             double distancePoint1 = Distance(x1, y1);
  33.             double distancePoint2 = Distance(x2, y2);
  34.             double distancePoint3 = Distance(x3, y3);
  35.             double distancePoint4 = Distance(x4, y4);
  36.             double lengthPoint12= Distance(x1 - x2, y1 - y2);
  37.             double lengthPoint34= Distance(x3 - x4, y3 - y4);
  38.  
  39.             if (lengthPoint12 >= lengthPoint34)
  40.             {
  41.                 if (distancePoint1 <= distancePoint2)
  42.                 {
  43.                     Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  44.                 }
  45.                 else
  46.                 {
  47.                     Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  48.                 }
  49.             }
  50.             else
  51.             {
  52.                 if (distancePoint3 <= distancePoint4)
  53.                 {
  54.                     Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  55.                 }
  56.  
  57.                 else
  58.                 {
  59.                     Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment