SHARE
TWEET

LongerLine

MilenaPetkanova Oct 6th, 2017 (edited) 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace _0509_LongerLine
  4. {
  5.     class LongerLine
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double xx1 = double.Parse(Console.ReadLine());
  10.             double xy1 = double.Parse(Console.ReadLine());
  11.             double xx2 = double.Parse(Console.ReadLine());
  12.             double xy2 = double.Parse(Console.ReadLine());
  13.             double yx1 = double.Parse(Console.ReadLine());
  14.             double yy1 = double.Parse(Console.ReadLine());
  15.             double yx2 = double.Parse(Console.ReadLine());
  16.             double yy2 = double.Parse(Console.ReadLine());
  17.  
  18.             double dX = GetDistBtwnTwoPoints(xx1, xx2, xy1, xy2);
  19.             double dY = GetDistBtwnTwoPoints(yx1, yx2, yy1, yy2);
  20.  
  21.             if (dX >= dY)
  22.             {
  23.                 PrintClosestPointsFirst(xx1, xy1, xx2, xy2);
  24.             }
  25.             else
  26.             {
  27.                 PrintClosestPointsFirst(yx1, yy1, yx2, yy2);
  28.             }
  29.         }
  30.  
  31.         static double GetDistBtwnTwoPoints(double x1, double x2, double y1, double y2)
  32.         {
  33.             double dX = x1 - x2;
  34.             double dY = y1 - y2;
  35.             double dXY = Math.Sqrt(dX * dX + dY * dY);
  36.             return dXY;
  37.         }
  38.  
  39.         static void PrintClosestPointsFirst(double x1, double y1, double x2, double y2)
  40.         {
  41.             double diagonalX1Y1 = Math.Sqrt(x1 * x1 + y1 * y1);
  42.             double diagonalX2Y2 = Math.Sqrt(x2 * x2 + y2 * y2);
  43.             if (diagonalX1Y1 <= diagonalX2Y2)
  44.             {
  45.                 Console.WriteLine("({0}, {1})({2}, {3})", x1, y1, x2, y2);
  46.             }
  47.             else
  48.             {
  49.                 Console.WriteLine("({0}, {1})({2}, {3})", x2, y2, x1, x1);
  50.             }
  51.         }
  52.     }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top