aggressiveviking

03.PointOnSegment

Mar 4th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03.PointOnSegment
  4. {
  5.     class PointOnSegment
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int first = int.Parse(Console.ReadLine());
  10.             int second = int.Parse(Console.ReadLine());
  11.             int point = int.Parse(Console.ReadLine());
  12.  
  13.             int left = Math.Min(first, second);
  14.             int right = Math.Max(first, second);
  15.  
  16.             int distanceLeft = Math.Abs(left - point);
  17.             int distanceRight = Math.Abs(right - point);
  18.  
  19.             int minDistance = Math.Min(distanceLeft, distanceRight);
  20.  
  21.             if (point >= left && point <= right)
  22.             {
  23.                 Console.WriteLine("in");
  24.             }
  25.             else
  26.             {
  27.                 Console.WriteLine("out");
  28.             }
  29.  
  30.             Console.WriteLine(minDistance);
  31.  
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment