Guest User

Untitled

a guest
Jun 22nd, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 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.             double x2 = double.Parse(Console.ReadLine());
  12.             double y2 = double.Parse(Console.ReadLine());
  13.             double x3 = double.Parse(Console.ReadLine());
  14.             double y3 = double.Parse(Console.ReadLine());
  15.             double x4 = double.Parse(Console.ReadLine());
  16.             double y4 = double.Parse(Console.ReadLine());
  17.  
  18.             //double lenghtLine1 = CalculateLineLenght(x1, y1, x2, y2);
  19.             //double lenghtLine2 = CalculateLineLenght(x2, y2, x3, y3);
  20.  
  21.             double lenghtLine1 = CalculateLineLenght(x1, y1, x2, y2);
  22.             double lenghtLine2 = CalculateLineLenght(x3, y3, x4, y4);
  23.  
  24.  
  25.             if (lenghtLine1 >= lenghtLine2)
  26.             {
  27.                 bool isClosest = CheckClosestToZero(x1, y1, x2, y2);
  28.  
  29.                 if (isClosest)
  30.                 {
  31.                     Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  32.                 }
  33.  
  34.                 else
  35.                 {
  36.                     Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  37.  
  38.                 }
  39.  
  40.             }
  41.  
  42.             else
  43.             {
  44.                 bool isClosest = CheckClosestToZero(x3, y3, x4, y4);
  45.                 if (isClosest)
  46.                 {
  47.                     Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  48.                 }
  49.  
  50.                 else
  51.                 {
  52.                     Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  53.                 }
  54.  
  55.             }
  56.  
  57.         }
  58.  
  59.         static double CalculateLineLenght(double x1, double y1, double x2, double y2)
  60.         {
  61.             return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
  62.         }
  63.  
  64.         static bool CheckClosestToZero(double x1, double y1, double x2, double y2)
  65.         {
  66.             double distance1 = Math.Sqrt(Math.Pow(x1, 2) + Math.Pow(y1, 2));
  67.             double distance2 = Math.Sqrt(Math.Pow(x2, 2) + Math.Pow(y2, 2));
  68.  
  69.             if (distance1 <= distance2)
  70.             {
  71.                 return true;
  72.             }
  73.  
  74.             return false;
  75.         }
  76.  
  77.  
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment