Advertisement
loter

Longer Line

Feb 5th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PLongest_Line
  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. double x3 = double.Parse(Console.ReadLine());
  14. double y3 = double.Parse(Console.ReadLine());
  15. double x4 = double.Parse(Console.ReadLine());
  16. double y4 = double.Parse(Console.ReadLine());
  17.  
  18. string result = FindLongestLine(x1, y1, x2, y2, x3, y3, x4, y4);
  19.  
  20. if (result == "line1")
  21. {
  22. CloserPoint1(x1, y1, x2, y2);
  23. }
  24. else
  25. {
  26. CloserPoint2(x3, y3, x4, y4);
  27. }
  28. }
  29.  
  30. private static void CloserPoint2(double x3, double y3, double x4, double y4)
  31. {
  32. double a = Math.Sqrt(x3 * x3 + y3 * y3);
  33. double b = Math.Sqrt(x4 * x4 + y4 * y4);
  34.  
  35. if (a <= b)
  36. {
  37. Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  38. }
  39. else
  40. {
  41. Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  42. }
  43. }
  44.  
  45. static void CloserPoint1(double x1, double y1, double x2, double y2)
  46. {
  47. double a = Math.Sqrt(x1 * x1 + y1 * y1);
  48. double b = Math.Sqrt(x2 * x2 + y2 * y2);
  49.  
  50. if (a <= b)
  51. {
  52. Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  53. }
  54. else
  55. {
  56. Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  57. }
  58. }
  59.  
  60. static string FindLongestLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  61. {
  62. double a = Math.Abs(x1) + Math.Abs(x2);
  63. double b = Math.Max(Math.Abs(y1), Math.Abs(y2)) - Math.Min(Math.Abs(y1), Math.Abs(y2));
  64. double line1 = Math.Sqrt(a * a + b * b);
  65.  
  66. double c = Math.Abs(x3) + Math.Abs(x4);
  67. double d = Math.Max(Math.Abs(y3), Math.Abs(y4)) - Math.Min(Math.Abs(y3), Math.Abs(y4));
  68. double line2 = Math.Sqrt(c * c + d * d);
  69.  
  70. if (line1 >= line2)
  71. {
  72. return "line1";
  73. }
  74. else
  75. {
  76. return "line2";
  77. }
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement