Advertisement
Guest User

Untitled

a guest
Mar 29th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. using System;
  2.  
  3. class Test
  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.  
  12. double x3 = double.Parse(Console.ReadLine());
  13. double y3 = double.Parse(Console.ReadLine());
  14. double x4 = double.Parse(Console.ReadLine());
  15. double y4 = double.Parse(Console.ReadLine());
  16.  
  17. PrintTheLongerLine(x1, y1, x2, y2, x3, y3, x4, y4);
  18. }
  19.  
  20. static void PrintTheLongerLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  21. {
  22. double firstLineLenght = GetLineLenght(x1, x2, y1, y2);
  23. double secondLineLenght = GetLineLenght(x3, x4, y3, y4);
  24.  
  25. double firstPointDistance = 0;
  26. double secondPointDistance = 0;
  27.  
  28. if (firstLineLenght >= secondLineLenght) // Печатаме точките на 1-вата линия x1, y1, x2, y2
  29. {
  30. firstPointDistance = GetDistanceToCenter(x1, y1);
  31. secondLineLenght = GetDistanceToCenter(x2, y2);
  32.  
  33. if (firstPointDistance > secondPointDistance) // вторите точки са по-близо => печатаме тях първо
  34. {
  35. Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  36. }
  37. else // първите точки са по-близо => печатаме тях първо
  38. {
  39. Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  40. }
  41. }
  42.  
  43. else // Печатаме точките на 2-рата линия x3, y3, x4, y4
  44. {
  45. firstPointDistance = GetDistanceToCenter(x3, y3);
  46. secondPointDistance = GetDistanceToCenter(x4, y4);
  47.  
  48. if (firstPointDistance > secondPointDistance) // вторите точки са по-близо => печатаме тях първо
  49. {
  50. Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  51. }
  52. else // първите точки са по-близо => печатаме тях първо
  53. {
  54. Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  55. }
  56. }
  57. }
  58.  
  59. static double GetLineLenght(double x1, double x2, double y1, double y2)
  60. {
  61. return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
  62. }
  63.  
  64. static double GetDistanceToCenter(double x, double y)
  65. {
  66. return Math.Sqrt(Math.Pow((x - 0), 2) + Math.Pow((y - 0),2));
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement