Advertisement
plamen27

Longer Line fixed

Sep 27th, 2016
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System;
  2.  
  3. class LongerLine
  4. {
  5. static void Main()
  6. {
  7. double x1 = double.Parse(Console.ReadLine());
  8. double y1 = double.Parse(Console.ReadLine());
  9. double x2 = double.Parse(Console.ReadLine());
  10. double y2 = double.Parse(Console.ReadLine());
  11. double x3 = double.Parse(Console.ReadLine());
  12. double y3 = double.Parse(Console.ReadLine());
  13. double x4 = double.Parse(Console.ReadLine());
  14. double y4 = double.Parse(Console.ReadLine());
  15.  
  16. PrintLongerLine(x1, y1, x2, y2, x3, y3, x4, y4);
  17. }
  18.  
  19. static void PrintLongerLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  20. {
  21. double firstLineLen = Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
  22. double secondLineLen = Math.Sqrt(Math.Pow((x4 - x3), 2) + Math.Pow((y4 - y3), 2));
  23.  
  24. if (firstLineLen >= secondLineLen)
  25. {
  26. bool isFirstCloser = closerPoint(x1, y1, x2, y2);
  27. if (isFirstCloser)
  28. {
  29. Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  30. }
  31. else
  32. {
  33. Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  34. }
  35. }
  36. else
  37. {
  38. bool isFirstCloser = closerPoint(x3, y3, x4, y4);
  39. if (isFirstCloser)
  40. {
  41. Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  42. }
  43. else
  44. {
  45. Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  46. }
  47. }
  48. }
  49.  
  50. private static bool closerPoint(double x1, double y1, double x2, double y2)
  51. {
  52. double firstPointLine = Math.Sqrt(x1*x1 + y1*y1);
  53. double secondPointLine = Math.Sqrt(x2 * x2 + y2 * y2);
  54. bool isFirstCloser = true;
  55. if (firstPointLine<=secondPointLine)
  56. {
  57. isFirstCloser = true;
  58. }
  59. else
  60. {
  61. isFirstCloser = false;
  62. }
  63. return isFirstCloser;
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement