GerganaTsirkova

LongerLine

Dec 1st, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LongerLine
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. double firstLineX1 = double.Parse(Console.ReadLine());
  14. double firstLineY1 = double.Parse(Console.ReadLine());
  15. double firstLineX2 = double.Parse(Console.ReadLine());
  16. double firstLineY2 = double.Parse(Console.ReadLine());
  17. double secondLineX1 = double.Parse(Console.ReadLine());
  18. double secondLineY1 = double.Parse(Console.ReadLine());
  19. double secondLineX2 = double.Parse(Console.ReadLine());
  20. double secondLineY2 = double.Parse(Console.ReadLine());
  21.  
  22.  
  23. LongerLine(firstLineX1, firstLineX2, firstLineY1, firstLineY2, secondLineX1, secondLineX2, secondLineY1, secondLineY2);
  24. }
  25.  
  26. static void LongerLine(double firstLineX1, double firstLineX2, double firstLineY1, double firstLineY2, double secondLineX1, double secondLineX2, double secondLineY1, double secondLineY2)
  27. {
  28. double firstLineLenght = Math.Abs(Math.Abs(firstLineX1 * firstLineY2) - Math.Abs(firstLineX2 * firstLineY1));
  29. double secondLineLenght = Math.Abs(Math.Abs(secondLineX1 * secondLineY2) - Math.Abs(secondLineX2 * secondLineY1));
  30. if (firstLineLenght >= secondLineLenght)
  31. {
  32. ClosestPoint(firstLineX1, firstLineX2, firstLineY1, firstLineY2);
  33. }
  34. else
  35. {
  36. ClosestPoint(secondLineX1, secondLineX2, secondLineY1, secondLineY2);
  37. }
  38. }
  39. static void ClosestPoint(double x1, double x2, double y1, double y2)
  40. {
  41. double distanceFirstPoint = (Math.Abs(x1 * x1) + Math.Abs(x2 * x2));
  42. double distanceSecondPoint = (Math.Abs(y1 * y1) + Math.Abs(y2 * y2));
  43.  
  44. if (distanceFirstPoint <= distanceSecondPoint)
  45. Console.WriteLine("({0}, {1})({2}, {3})", x1, y1, x2, y2);
  46. else
  47. Console.WriteLine("({0}, {1})({2}, {3})", x2, y2, x1, y1);
  48.  
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment