fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int distance(int a, int b, int c, int d) {
  6. int ans = 0;
  7. if (a > b) {
  8. swap(a, b);
  9. }
  10. if (c > d) {
  11. swap(c, d);
  12. }
  13. if (b < c || a > d) {
  14. ans = 0;
  15. }
  16. else {
  17. int l = 0, r = 0;
  18. l = max(a, c);
  19. r = min(b, d);
  20. ans = r - l;
  21. }
  22. return ans;
  23. }
  24.  
  25. int main() {
  26. int x1, y1, x2, y2, x3, y3, x4, y4;
  27. cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
  28. if (x1 != x2) {
  29. cout << (y1 < max(y3, y4) && y1 > min(y3, y4) ? distance(x1, x2, x3, x4) : 0);
  30. }
  31. else {
  32. cout << (x1 < max(x3, x4) && x1 > min(x3, x4) ? distance(y1, y2, y3, y4) : 0);
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 4536KB
stdin
Standard input is empty
stdout
Standard output is empty