Advertisement
allia

отрезки

Nov 19th, 2020 (edited)
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. struct otrezok
  7. {
  8.   int x = 0, y = 0, length = 0;
  9.  
  10.   void perestanovka ()
  11.   {
  12.     if (x > y)
  13.      swap(x, y);
  14.   }
  15.   void shet ()
  16.   {
  17.     if (x != 0 && y != 0)
  18.      length = y - x +1;
  19.     else if (x == y && x == 0)
  20.      length = 0;
  21.   }
  22. };
  23.  
  24. int main()
  25. {
  26.   otrezok A, B, result;
  27.   cin >> A.x >> A.y >> B.x >> B.y;
  28.  
  29.   A.perestanovka();
  30.   B.perestanovka();
  31.  
  32.   //cout << A.x << " " <<  A.y << " " << B.x << " " << B.y;
  33.   if (A.x >= B.x && A.x <= B.y)
  34.     {
  35.       result.x = A.x;
  36.       if (A.y >= B.x && A.y <= B.y)
  37.        result.y = A.y;
  38.       if (A.y >= B.x && A.y >= B.y)
  39.        result.y = B.y;
  40.     }
  41.   else if (B.x >= A.x && B.x <= A.y)
  42.     {
  43.       result.x = B.x;
  44.       if (B.y >= A.x && B.y <= A.y)
  45.        result.y = B.y;
  46.       if (B.y >= A.x && B.y >= A.y)
  47.        result.y = A.y;
  48.     };
  49.  
  50. result.shet();
  51.  
  52. cout << result.length;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement