Advertisement
Guest User

LongerLine

a guest
Sep 27th, 2016
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class LongerLine
  5. {
  6.     static void Main()
  7.     {
  8.         double x1 = double.Parse(Console.ReadLine());
  9.         double y1 = double.Parse(Console.ReadLine());
  10.  
  11.         double x2 = double.Parse(Console.ReadLine());
  12.         double y2 = double.Parse(Console.ReadLine());
  13.  
  14.         double x3 = double.Parse(Console.ReadLine());
  15.         double y3 = double.Parse(Console.ReadLine());
  16.  
  17.         double x4 = double.Parse(Console.ReadLine());
  18.         double y4 = double.Parse(Console.ReadLine());
  19.  
  20.         double lineA = CalculateLineLength(x1, y1,x2,y2);
  21.         double lineB = CalculateLineLength(x3, y3, x4, y4);
  22.  
  23.    
  24.         if (lineA >= lineB && CheckCloserPoint(x1,y1,x2,y2))
  25.         {
  26.             Console.Write($"({x1}, {y1}) ({x2}, {y2})");
  27.         }
  28.         else if(lineA >= lineB && CheckCloserPoint(x1, y1, x2, y2) == false)
  29.         {
  30.             Console.Write($"({x2}, {y2}) ({x1}, {y1})");
  31.         }
  32.         else if (lineA < lineB && CheckCloserPoint(x3, y3, x4, y4))
  33.         {
  34.             Console.Write($"({x3}, {y3}) ({x4}, {y4})");
  35.         }
  36.         else if(lineA < lineB && CheckCloserPoint(x3, y3, x4, y4) == false)
  37.         {
  38.             Console.Write($"({x4}, {y4})({x3}, {y3})");
  39.         }
  40.  
  41.     }
  42.  
  43.     private static bool CheckCloserPoint(double x1, double y1, double x2, double y2)
  44.     {
  45.         bool isCloserToZero = false;
  46.         double dist1 = Math.Sqrt(Math.Pow(x1, 2) + Math.Pow(y1, 2));
  47.         double dist2 = Math.Sqrt(Math.Pow(x2, 2) + Math.Pow(y2, 2));
  48.  
  49.         if (dist1 <= dist2)
  50.         {
  51.             isCloserToZero = true;
  52.         }
  53.         return isCloserToZero;
  54.     }
  55.  
  56.     private static double CalculateLineLength(double x1, double y1, double x2, double y2)
  57.     {
  58.         double lineLength = Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
  59.         return lineLength;
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement