GerryM

Longer Line

Nov 4th, 2016
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication12
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double x1 = double.Parse(Console.ReadLine());
  14.             double y1 = double.Parse(Console.ReadLine());
  15.             double x2 = double.Parse(Console.ReadLine());
  16.             double y2 = double.Parse(Console.ReadLine());
  17.             double x3 = double.Parse(Console.ReadLine());
  18.             double y3 = double.Parse(Console.ReadLine());
  19.             double x4 = double.Parse(Console.ReadLine());
  20.             double y4 = double.Parse(Console.ReadLine());
  21.             if (LineWidth(x1, y1, x2, y2) >= LineWidth(x3, y3, x4, y4))
  22.             {
  23.                 if (CloserPoint(x1, y1, x2, y2))
  24.                 {
  25.                     Console.WriteLine("({0}, {1})({2}, {3})", x1, y1, x2, y2);
  26.                 }
  27.                 else
  28.                 {
  29.                     Console.WriteLine("({0}, {1})({2}, {3})", x2, y2, x1, y1);
  30.                 }
  31.             }
  32.             else {
  33.                 if (CloserPoint(x3, y3, x4, y4))
  34.                 {
  35.                     Console.WriteLine("({0}, {1})({2}, {3})", x3, y3, x4, y4);
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.WriteLine("({0}, {1})({2}, {3})", x4, y4, x3, y3);
  40.                 }
  41.             }
  42.         }
  43.         static double LineWidth(double x1, double y1, double x2, double y2) {
  44.             double xCoordinate = x2 - x1;
  45.             double yCoordinate = y2 - y1;
  46.             double width = Math.Sqrt(Math.Pow(xCoordinate, 2) + Math.Pow(yCoordinate, 2));  
  47.                      
  48.             return width;
  49.         }
  50.         static bool CloserPoint(double x1,double y1,double x2,double y2) {
  51.            bool isCloser = false;
  52.             if ((Math.Abs(x1) <= Math.Abs(x2)) && (Math.Abs(y1) <=Math.Abs(y2))) {
  53.                 isCloser = true;
  54.             }
  55.  
  56.             return isCloser;
  57.  
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment