Advertisement
AlexTasev

09_LongerLine

May 25th, 2018
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09_LongerLine
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  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.             double lineOneLenght = FindLongerLine(x1, y1, x2, y2);
  22.             double lineTwoLenght = FindLongerLine(x3, y3, x4, y4);
  23.  
  24.             if (lineOneLenght >= lineTwoLenght)
  25.             {
  26.                 double pointOneToCent = FindClosestPoint(x1, y1);
  27.                 double pointTwoToCent = FindClosestPoint(x2, y2);
  28.  
  29.                 if (pointOneToCent <= pointTwoToCent)
  30.                 {
  31.                     Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  32.                 }
  33.                 else
  34.                 {
  35.                     Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  36.                 }
  37.             }
  38.  
  39.             else
  40.             {
  41.                 double pointOneToCent = FindClosestPoint(x3, y3);
  42.                 double pointTwoToCent = FindClosestPoint(x4, y4);
  43.  
  44.                 if (pointOneToCent <= pointTwoToCent)
  45.                 {
  46.                     Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  47.                 }
  48.                 else
  49.                 {
  50.                     Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  51.                 }
  52.             }
  53.         }
  54.  
  55.         static double FindLongerLine(double x1, double y1, double x2, double y2)
  56.         {
  57.             double result = Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2);
  58.             return result;
  59.         }
  60.  
  61.         static double FindClosestPoint(double coordinateX1, double coordinateY1)
  62.         {
  63.             double distancePointToCent = Math.Sqrt(Math.Pow(coordinateX1, 2) + Math.Pow(coordinateY1, 2));
  64.             return distancePointToCent;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement