Advertisement
AlexJC

Point on Segment

Aug 27th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 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 Point_on_Segment
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int first = int.Parse(Console.ReadLine());
  14. int second = int.Parse(Console.ReadLine());
  15. int point = int.Parse(Console.ReadLine());
  16. int minDist = 0;
  17. int min = 0;
  18. int max = 0;
  19. int difFirst = Math.Abs(first - point);
  20. int difSecond = Math.Abs(second - point);
  21.  
  22. if (first < second)
  23. {
  24. min = first;
  25. max = second;
  26. }
  27. else
  28. {
  29. min = second;
  30. max = first;
  31. }
  32.  
  33. if (difFirst < difSecond)
  34. {
  35. minDist = difFirst;
  36. }
  37. else
  38. {
  39. minDist = difSecond;
  40. }
  41. if (point >= min && point <= max)
  42. {
  43. Console.WriteLine("in");
  44. Console.WriteLine(minDist);
  45. }
  46. else
  47. {
  48. Console.WriteLine("out");
  49. Console.WriteLine(minDist);
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement