Advertisement
Guest User

Untitled

a guest
Jul 1st, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 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 PointInRectangle
  8. {
  9. public class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. string[] input = Console.ReadLine().Split(' ');
  15. int topLeftX = int.Parse(input[0]);
  16. int topLeftY = int.Parse(input[1]);
  17. int bottomRightX = int.Parse(input[2]);
  18. int bottomRightY = int.Parse(input[3]);
  19.  
  20. Point a = new Point(topLeftX, topLeftY);
  21. Point b = new Point(bottomRightX, bottomRightY);
  22. Rectangle rec = new Rectangle(a, b);
  23.  
  24. int N = int.Parse(Console.ReadLine());
  25.  
  26. for (int i = 0; i < N; i++)
  27. {
  28. string[] coords = Console.ReadLine().Split(' ');
  29. int givenPointX = int.Parse(coords[0]);
  30. int givenPointY = int.Parse(coords[1]);
  31. Point givenPoint = new Point(givenPointX, givenPointY);
  32. bool rr = rec.Contains(givenPoint);
  33. Console.WriteLine(rr);
  34.  
  35. }
  36.  
  37. }
  38. }
  39. }
  40.  
  41.  
  42. namespace PointInRectangle
  43. {
  44. public class Point
  45. {
  46.  
  47. public int XCoordinate { get; set; }
  48.  
  49. public int YCoordinate { get; set; }
  50.  
  51. public Point(int xCoordinate, int yCoordinate)
  52. {
  53. this.XCoordinate = xCoordinate;
  54. this.YCoordinate = yCoordinate;
  55. }
  56.  
  57. }
  58. }
  59.  
  60.  
  61.  
  62.  
  63. using System;
  64. using System.Collections.Generic;
  65. using System.Linq;
  66. using System.Text;
  67. using System.Threading.Tasks;
  68.  
  69. namespace PointInRectangle
  70. {
  71. public class Rectangle
  72. {
  73.  
  74. public Point Point1 { get; set; }
  75. public Point Point2 { get; set; }
  76.  
  77. public Rectangle(Point point1, Point point2)
  78. {
  79. this.Point1 = point1;
  80. this.Point2 = point2;
  81. }
  82.  
  83.  
  84. public bool Contains(Point point)
  85. {
  86.  
  87.  
  88. if (point.XCoordinate < Point1.XCoordinate || point.XCoordinate > Point2.XCoordinate)
  89. {
  90. return false;
  91. }
  92.  
  93. else if (point.YCoordinate < Point1.YCoordinate || point.YCoordinate > Point2.YCoordinate)
  94. {
  95. return false;
  96. }
  97. else
  98. {
  99. return true;
  100. }
  101.  
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement