fork download
  1. class Main
  2. {
  3. static int distance(int a, int b, int c, int d)
  4. {
  5. int ans = 0;
  6. if (a > b)
  7. {
  8. int temp = a;
  9. a = b;
  10. b = temp;
  11. }
  12. if (c > d)
  13. {
  14. int temp = c;
  15. c = d;
  16. d = temp;
  17. }
  18. if (b < c || a > d)
  19. {
  20. ans = 0;
  21. }
  22. else
  23. {
  24. int l = 0, r = 0;
  25. l = Math.max(a, c);
  26. r = Math.min(b, d);
  27. ans = r - l;
  28. }
  29. return ans;
  30. }
  31. public static void main (String[] args)
  32. {
  33. java.util.Scanner in = new java.util.Scanner(System.in);
  34. int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();
  35. int x3 = in.nextInt(), y3 = in.nextInt(), x4 = in.nextInt(), y4 = in.nextInt();
  36. if (x1 != x2)
  37. {
  38. System.out.println(y1 < Math.max(y3, y4) && y1 > Math.min(y3, y4) ? distance(x1, x2, x3, x4) : 0);
  39. }
  40. else
  41. {
  42. System.out.println(x1 < Math.max(x3, x4) && x1 > Math.min(x3, x4) ? distance(y1, y2, y3, y4) : 0);
  43. }
  44. }
  45. }
Success #stdin #stdout 0.1s 35424KB
stdin
4 1 9 1 2 3 5 -2
stdout
1