Advertisement
BallistixXx

9. Longer Line

Feb 3rd, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. //Doesn't fully work!
  2.  
  3. using System;
  4.  
  5. namespace LongerLine
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int NumOfPoints = 4; int ArraySize = (int)Math.Log(1.0 * NumOfPoints, 2);
  12.  
  13. double[] Point = new double[NumOfPoints * 2];
  14. double[] LineDistance = new double[ArraySize];
  15.  
  16. int Index = 0; double LastDistance = 0; int MaxIndex = 0;
  17.  
  18. for (int j = -1, i = 0; i < NumOfPoints; i++)
  19. {
  20. Point[Index++] = double.Parse(Console.ReadLine());
  21. Point[Index++] = double.Parse(Console.ReadLine());
  22.  
  23. if ((i + 1) % 2 == 0)
  24. {
  25. LineDistance[++j] = FindDistanceOfLine(Point[Index - 4], Point[Index - 3], Point[Index - 2], Point[Index - 1]);
  26.  
  27. if(LastDistance == LineDistance[j])
  28. {
  29. MaxIndex = j - 1;
  30. }
  31. else if (LastDistance < LineDistance[j])
  32. {
  33. LastDistance = LineDistance[j];
  34. MaxIndex = j;
  35. }
  36. }
  37. }
  38. double Distance1 = FindDistanceToPoint(Point[MaxIndex * NumOfPoints], Point[MaxIndex * NumOfPoints + 1]);
  39. double Distance2 = FindDistanceToPoint(Point[MaxIndex * NumOfPoints + 2], Point[MaxIndex * NumOfPoints + 3]);
  40.  
  41. if(Distance2 > Distance1)
  42. {
  43. Console.WriteLine($"({Point[MaxIndex * NumOfPoints]}, {Point[MaxIndex * NumOfPoints + 1]})" +
  44. $"({Point[MaxIndex * NumOfPoints + 2]}, {Point[MaxIndex * NumOfPoints + 3]})");
  45. }
  46. else
  47. {
  48. Console.WriteLine($"({Point[MaxIndex * NumOfPoints + 2]}, {Point[MaxIndex * NumOfPoints + 3]})" +
  49. $"({Point[MaxIndex * NumOfPoints]}, {Point[MaxIndex * NumOfPoints + 1]})");
  50. }
  51. }
  52.  
  53. static double FindDistanceOfLine(double Point1, double Point2, double Point3, double Point4)
  54. {
  55. return Math.Abs(Math.Sqrt(Math.Pow((Point3 - Point1), 2) + Math.Pow((Point4 - Point2), 2)));
  56. }
  57.  
  58. static double FindDistanceToPoint(double X, double Y)
  59. {
  60. return Math.Abs(Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2)));
  61. }
  62.  
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement