JuliaPetkova

Untitled

Jun 10th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 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 length1L2 = GetLength(x1, y1, x2, y2);
  21. double length3L4 = GetLength(x3, y3, x4, y4);
  22.  
  23. double l1 = GetLengthToZeroPoint(x1, y1);
  24. double l2 = GetLengthToZeroPoint(x2, y2);
  25. double l3 = GetLengthToZeroPoint(x3, y3);
  26. double l4 = GetLengthToZeroPoint(x4, y4);
  27.  
  28.  
  29. if (length1L2 >= length3L4)
  30. {
  31. string smallestToZero = GetSmallestLengthToZero(l1, l2, l3, l4);
  32. Console.WriteLine(smallestToZero);
  33. }
  34. else
  35. {
  36. string smallestToZero = GetSmallestLengthToZero(l1, l2, l3, l4);
  37. Console.WriteLine(smallestToZero);
  38. }
  39. }
  40.  
  41. static string GetSmallestLengthToZero(double l1, double l2, double l3, double l4)
  42. {
  43.  
  44. string smallestToZero = string.Empty;
  45.  
  46. if (l1 < l2)
  47. {
  48. smallestToZero = ($"({x1}, {y1})({x2}, {y2})");
  49. }
  50. else
  51. {
  52. smallestToZero = ($"({x2}, {y2})({x1}, {y1})");
  53. }
  54. return smallestToZero;
  55. }
  56.  
  57.  
  58. static double GetLengthToZeroPoint(double x, double y)
  59. {
  60. return Math.Sqrt(Math.Pow((x), 2) + Math.Pow(y, 2));
  61. }
  62.  
  63. static double GetLength(double xOne, double yOne, double xTwo, double yTwo)
  64. {
  65. double x = Math.Abs(xOne - xTwo);
  66. double y = Math.Abs(yOne - yTwo);
  67. return Math.Sqrt(Math.Pow((x), 2) + Math.Pow(y, 2));
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment