Advertisement
Guest User

Point in Figure Second Solution

a guest
Oct 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 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 point_in_figure
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int h = int.Parse(Console.ReadLine());
  14. int x = int.Parse(Console.ReadLine());
  15. int y = int.Parse(Console.ReadLine());
  16. bool inside = (x > 0 && x < 3 * h) && (y > 0 && y < h)
  17. || (x > 0 && x > h) && (y > 0 && x < 2*h && y < 4 * h);
  18.  
  19. // Create a bool variable to check if point is exactly on the border
  20.  
  21. bool onRegtangle = (
  22. y == h && (x >= 0 && x <= h)
  23. || y == 0 && (x >= 0 && x <= 3 * h)
  24. || (x == 0 && y >= 0 && y <= h)
  25. || (x == 3 * h && y >= 0 && y <= h)
  26. || (y == 4 * h && (x >= h && x <= 2 * h))
  27. || y == h && (x >= 2*h && x <= 3*h)
  28. || (x == h && y >= h && y <= 4 * h)
  29. || (x == 2 * h && y >= h && y <= 4 * h));
  30. string result = "";
  31.  
  32. if (inside)
  33. {
  34. result = "inside";
  35. }
  36. else if (!inside && !onRegtangle)
  37. {
  38. result = "outside";
  39. }
  40. else
  41. { result = "border"; }
  42.  
  43. Console.WriteLine(result);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement