JuliaPetkova

Untitled

Jun 10th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _5_2_09_LongerLine
  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.  
  20. double lengthL1 = GetLength(x1, y1, x2, y2);
  21. double lengthL2 = GetLength(x3, y3, x4, y4);
  22.  
  23. if (lengthL1 > lengthL2)
  24. {
  25. string smalLengthToZero1 = GetSmallestLengthToZero1(x1, y1, x2, y2);
  26. Console.WriteLine(smalLengthToZero1);
  27. }
  28. else if (lengthL1 < lengthL2)
  29. {
  30. string smalLengthToZero2 = GetSmallestLengthToZero2(x3, y3, x4, y4);
  31. Console.WriteLine(smalLengthToZero2);
  32. }
  33. else
  34. {
  35. Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  36. }
  37.  
  38. }
  39.  
  40. static string GetSmallestLengthToZero1(double x1, double y1, double x2, double y2)
  41. {
  42. double lengthL10 = GetLengthToZeroPoint(x1, y1);
  43. double lengthL20 = GetLengthToZeroPoint(x2, y2);
  44.  
  45. string smalLengthToZero1 = string.Empty;
  46.  
  47. if (lengthL10 < lengthL20)
  48. {
  49. smalLengthToZero1 = ($"({x1}, {y1})({x2}, {y2})");
  50. }
  51. else if (lengthL10 >= lengthL20)
  52. {
  53. smalLengthToZero1 = ($"({x2}, {y2})({x1}, {y1})");
  54. }
  55. return smalLengthToZero1;
  56. }
  57.  
  58.  
  59. static string GetSmallestLengthToZero2(double x3, double y3, double x4, double y4)
  60. {
  61. double lengthL30 = GetLengthToZeroPoint(x3, y3);
  62. double lengthL40 = GetLengthToZeroPoint(x4, y4);
  63.  
  64. string smalLengthToZero2 = string.Empty;
  65.  
  66. if (lengthL30 < lengthL40)
  67. {
  68. smalLengthToZero2 = ($"({x3}, {y3})({x4}, {y4})");
  69. }
  70. else if (lengthL30 >= lengthL40)
  71. {
  72. smalLengthToZero2 = ($"({x4}, {y4})({x3}, {y3})");
  73. }
  74. return smalLengthToZero2;
  75. }
  76.  
  77. static double GetLengthToZeroPoint(double x, double y)
  78. {
  79. return Math.Sqrt(Math.Pow((x), 2) + Math.Pow(y, 2));
  80. }
  81.  
  82. static double GetLength(double xOne, double yOne, double xTwo, double yTwo)
  83. {
  84. double x = Math.Abs(xOne - xTwo);
  85. double y = Math.Abs(yOne - yTwo);
  86. return Math.Sqrt(Math.Pow((x), 2) + Math.Pow(y, 2));
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment