Advertisement
Spocoman

03. Longer Line

Jan 30th, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LongerLine
  4.  
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             double x1 = double.Parse(Console.ReadLine());
  11.             double y1 = double.Parse(Console.ReadLine());
  12.             double x2 = double.Parse(Console.ReadLine());
  13.             double y2 = double.Parse(Console.ReadLine());
  14.  
  15.             double x3 = double.Parse(Console.ReadLine());
  16.             double y3 = double.Parse(Console.ReadLine());
  17.             double x4 = double.Parse(Console.ReadLine());
  18.             double y4 = double.Parse(Console.ReadLine());
  19.  
  20.             LongestLine(x1, y1, x2, y2, x3, y3, x4, y4);
  21.         }
  22.  
  23.         static void ClosestToZero(double a, double b, double c, double d)
  24.         {
  25.             double first = Math.Sqrt(Math.Pow(Math.Abs(a), 2) + Math.Pow(Math.Abs(b), 2));
  26.             double second = Math.Sqrt(Math.Pow(Math.Abs(c), 2) + Math.Pow(Math.Abs(d), 2));
  27.  
  28.             Console.WriteLine(first > second ? $"({c}, {d})({a}, {b})" : $"({a}, {b})({c}, {d})");
  29.         }
  30.  
  31.         static void LongestLine(double a, double b, double c, double d, double e, double f, double g, double h)
  32.         {
  33.             double firstLine = Math.Sqrt(Math.Pow(Math.Abs(a - c), 2) + Math.Pow(Math.Abs(b - d), 2));
  34.             double secondLine = Math.Sqrt(Math.Pow(Math.Abs(e - g), 2) + Math.Pow(Math.Abs(f - h), 2));
  35.  
  36.             if (firstLine >= secondLine)
  37.             {
  38.                 ClosestToZero(a, b, c, d);
  39.             }
  40.             else
  41.             {
  42.                 ClosestToZero(e, f, g, h);
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement