Advertisement
YavorJS

Longer Line - 80%

Sep 23rd, 2016
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main(string[] args)
  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. double lengthFirstLine = lineLength(x1, y1, x2, y2);
  18. double lengthSecondLine = lineLength(x3, y3, x4, y4);
  19.  
  20. if (lengthFirstLine >= lengthSecondLine)
  21. {
  22. bool isFirstCloser = closerPoint(x1, y1, x2, y2);
  23. if (isFirstCloser) Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
  24. else Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
  25. }
  26. else if (lengthFirstLine < lengthSecondLine)
  27. {
  28. bool isFirstCloser = closerPoint(x3, y3, x4, y4);
  29. if (isFirstCloser) Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
  30. else Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
  31. }
  32. }
  33.  
  34. private static double lineLength(double x1, double y1, double x2, double y2)
  35. {
  36. double a1 = Math.Abs(x1) + Math.Abs(x2);
  37. double b1 = Math.Abs(Math.Abs(y1) - Math.Abs(y2));
  38. return Math.Sqrt(a1 * a1 + b1 * b1);
  39. }
  40.  
  41. private static bool closerPoint(double x1, double y1, double x2, double y2)
  42. {
  43. double c1 = Math.Sqrt(x1 * x1 + y1 * y1);
  44. double c2 = Math.Sqrt(x2 * x2 + y2 * y2);
  45. bool closerOrNot = true;
  46. if (c1 < c2) closerOrNot = true;
  47. else if (c1 > c2) closerOrNot = false;
  48. return closerOrNot;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement