Advertisement
Aborigenius

DistanceBetweenTwoPoints

Aug 18th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 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 Next
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // DateTime input = DateTime.ParseExact(
  14.             //     Console.ReadLine(), "d-M-yyyy", System.Globalization.CultureInfo.InvariantCulture
  15.             //     );
  16.             //
  17.             // Console.WriteLine(input.DayOfWeek);
  18.             Point firstPoint = Point.ParsePoint(Console.ReadLine());
  19.             Point secondPoint = Point.ParsePoint(Console.ReadLine());
  20.  
  21.             double distance = CalcDistance(firstPoint, secondPoint);
  22.  
  23.             Console.WriteLine($"{distance:f3}");
  24.         }
  25.  
  26.         private static double CalcDistance(Point firstPoint, Point secondPoint)
  27.         {
  28.             double sideA = Math.Pow((firstPoint.X - secondPoint.X), 2);
  29.             double sideB = Math.Pow((firstPoint.Y - secondPoint.Y), 2);
  30.  
  31.             return Math.Sqrt(sideA + sideB);
  32.  
  33.         }
  34.  
  35.         private static Point ReadPoint(string input)
  36.         {
  37.             int[] inputData = input.Split(' ').Select(int.Parse).ToArray();
  38.             return new Point(inputData[0], inputData[1]);
  39.         }
  40.  
  41.         class Point
  42.         {
  43.             public int X { get; set; }
  44.             public int Y { get; set; }
  45.  
  46.             public Point(int xCoord, int yCoord)
  47.             {
  48.                 X = xCoord;
  49.                 Y = yCoord;
  50.             }
  51.  
  52.             public static Point ParsePoint(string input)
  53.             {
  54.                 int[] inputData = input.Split(' ').Select(int.Parse).ToArray();
  55.                 return new Point(inputData[0], inputData[1]);
  56.  
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement