Advertisement
SavaIv

Untitled

May 29th, 2020
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._Longer_Line2
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double x1 = double.Parse(Console.ReadLine());
  10. double y1 = double.Parse(Console.ReadLine());
  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. double x4 = double.Parse(Console.ReadLine());
  17. double y4 = double.Parse(Console.ReadLine());
  18.  
  19. double line1 = GetDistanceBetweenTwoPoints(x1, y1, x2, y2);
  20. double line2 = GetDistanceBetweenTwoPoints(x3, y3, x4, y4);
  21.  
  22. // if the first point (from the piar) is closer to zero = true
  23. bool line1Point1IsCloserToZero = aPointCloserToTheZero(x1, y1, x2, y2);
  24. bool line2Point1IsCloserToZero = aPointCloserToTheZero(x3, y3, x4, y4);
  25.  
  26. if (line1 >= line2)
  27. {
  28. if (line1Point1IsCloserToZero)
  29. {
  30. Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  31. }
  32. else
  33. {
  34. Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  35. }
  36. }
  37. else
  38. {
  39. if (line2Point1IsCloserToZero)
  40. {
  41. Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  42. }
  43. else
  44. {
  45. Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  46. }
  47. }
  48.  
  49. //Console.WriteLine("Hello World!");
  50. }
  51.  
  52. private static double GetDistanceBetweenTwoPoints(double x1, double y1, double x2, double y2)
  53. {
  54. double sideA = Math.Abs(x2 - x1);
  55. double sideB = Math.Abs(y2 - y1);
  56.  
  57. double sideC = Math.Sqrt((sideA * sideA) + (sideB * sideB));
  58.  
  59. return sideC;
  60. }
  61.  
  62. private static bool aPointCloserToTheZero(double x1, double y1, double x2, double y2)
  63. {
  64. double c1 = GetHypotenuse(x1, y1);
  65. double c2 = GetHypotenuse(x2, y2);
  66.  
  67. bool result = true;
  68.  
  69. if (c2 < c1)
  70. {
  71. result = false;
  72. }
  73.  
  74. return result;
  75. }
  76.  
  77. private static double GetHypotenuse(double a, double b)
  78. {
  79. //a = Math.Abs(a);
  80. //b = Math.Abs(b);
  81.  
  82. double c = Math.Sqrt((a * a) + (b * b));
  83.  
  84. return c;
  85. }
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement