Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Intersection
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. string[] input = Console.ReadLine().Split(' ');
  12. int x1 = int.Parse(input[0]);
  13. int y1 = int.Parse(input[1]);
  14. int x2 = int.Parse(input[2]);
  15. int y2 = int.Parse(input[3]);
  16. int x3 = int.Parse(input[4]);
  17. int y3 = int.Parse(input[5]);
  18. int x4 = int.Parse(input[6]);
  19. int y4 = int.Parse(input[7]);
  20. if (x1 == x2 && y1 == y2 || y3 == y4 && x3 == x4)
  21. {
  22. Console.WriteLine(0);
  23. return;
  24. }//proverka dali e otsechka
  25. if (y1 == y2 && x1 == x2 || y3 == y4 && x3 == x4 || y2 == y3 && x1 == x2 || y2 == y1 && x2 == x1)// ako 2 tochki syvpadat
  26. {
  27.  
  28. Console.WriteLine(1);
  29. return;
  30. }
  31. if (y1 == 0 && y2 == 0)// poneje delim na y, pravim otdelna proverka za nego.
  32. {
  33. if (x3 <= 0 && x4 >= 0 || x3 >= 0 && x4 <= 0)
  34. {
  35. Console.WriteLine(1);
  36. return;
  37. }
  38. }
  39. if (y3 == 0 && y4 == 0)// poneje delim na y, pravim otdelna proverka za nego.
  40. {
  41. if (x2 <= 0 && x1 >= 0 || x2 >= 0 && x1 <= 0)
  42. {
  43. Console.WriteLine(1);
  44. return;
  45. }
  46. }
  47. double a1 = y1 - y2;
  48. if (y2 < y1)
  49. {
  50. a1 = -a1;
  51. }
  52. double b1 = x2 - x1;
  53. if (x2 < x1)
  54. {
  55. b1 = -b1;
  56. }
  57. double c1 = (x1 - x2) * y1 + (y2 - y1) * x1;
  58. // Console.WriteLine(a1+"*x +" +b1 +"*y +"+c1 );
  59.  
  60. double a2 = y3 - y4;
  61. if (y4 < y3)
  62. {
  63. a1 = -a1;
  64. }
  65. double b2 = x4 - x3;
  66. if (x4 < x3)
  67. {
  68. b2 = -b2;
  69. }
  70. double c2 = (x3 - x4) * y3 + (y4 - y3) * x3;
  71. //Console.WriteLine(a2 + "*x +" + b2 + "*y +" + c2);
  72. double xPoint;
  73. double yPoint;
  74. double sA1 = a1;//pazim
  75. double sA2 = a2;
  76. double sB1 = b1;
  77.  
  78.  
  79. a1 = a2 * a1;//umnojavame
  80. b1 = a2 * b1;
  81. c1 = a2 * c1;
  82. a2 = a1 * a2;
  83. b2 = b2 * a2;
  84. c2 = c2 * a2;
  85.  
  86. b1 = b1 - b2;
  87.  
  88. b1 = b1 - b2;
  89. c1 = c1 - c2;
  90. yPoint = c1 / b1;
  91. if (y1 > y2)//minimalnoto
  92. {
  93. int temp = y1;
  94. y1 = y2;
  95. y2 = temp;
  96. }
  97. if (y3 > y4)//minimalnoto
  98. {
  99. int temp = y3;
  100. y3 = y4;
  101. y4 = temp;
  102. }
  103. // Console.WriteLine(yPoint);
  104. //Console.WriteLine();
  105. if (yPoint <= y2 && yPoint >= y1 && yPoint >= y3 && yPoint <= y4)
  106. {
  107. Console.WriteLine(1);
  108. }
  109. else Console.WriteLine(0);
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement