Advertisement
Guest User

Untitled

a guest
May 19th, 2018
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LongerLine
  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.  
  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.  
  18.             double x4 = double.Parse(Console.ReadLine());
  19.             double y4 = double.Parse(Console.ReadLine());
  20.  
  21.             LongerLine(x1, y1, x2, y2, x3, y3, x4, y4);
  22.         }
  23.  
  24.         static void LongerLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  25.         {
  26.  
  27.             if (DistanceBetweenTwoPoints(x1, y1, x2, y2) >= DistanceBetweenTwoPoints(x3, y3, x4, y4))
  28.             {
  29.                 ClosestPoint(x1, y1, x2, y2);
  30.             }
  31.             else
  32.             {
  33.                 ClosestPoint(x3, y3, x4, y4);
  34.             }
  35.         }
  36.  
  37.         static void ClosestPoint(double x1, double y1, double x2, double y2)
  38.         {
  39.             if (DistanceBetweenTwoPoints(x1, y1, 0, 0) <= DistanceBetweenTwoPoints(x2, y2, 0, 0))
  40.             {
  41.                 Console.Write($"({x1}, {y1})");
  42.                 Console.WriteLine($"({x2}, {y2})");
  43.             }
  44.             else
  45.             {
  46.                 Console.Write($"({x2}, {y2})");
  47.                 Console.WriteLine($"({x1}, {y1})");
  48.  
  49.             }
  50.         }
  51.  
  52.         static double DistanceBetweenTwoPoints(double x1, double y1, double x2, double y2)
  53.         {
  54.             double xDiff = x2 - x1;
  55.             double yDiff = y2 - y1;
  56.             return Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement