Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <algorithm>
- using namespace std;
- struct otrezok
- {
- int x = 0, y = 0, length = 0;
- void perestanovka ()
- {
- if (x > y)
- swap(x, y);
- }
- void shet ()
- {
- if (x != 0 && y != 0)
- length = y - x +1;
- else if (x == y && x == 0)
- length = 0;
- }
- };
- int main()
- {
- otrezok A, B, result;
- cin >> A.x >> A.y >> B.x >> B.y;
- A.perestanovka();
- B.perestanovka();
- //cout << A.x << " " << A.y << " " << B.x << " " << B.y;
- if (A.x >= B.x && A.x <= B.y)
- {
- result.x = A.x;
- if (A.y >= B.x && A.y <= B.y)
- result.y = A.y;
- if (A.y >= B.x && A.y >= B.y)
- result.y = B.y;
- }
- else if (B.x >= A.x && B.x <= A.y)
- {
- result.x = B.x;
- if (B.y >= A.x && B.y <= A.y)
- result.y = B.y;
- if (B.y >= A.x && B.y >= A.y)
- result.y = A.y;
- };
- result.shet();
- cout << result.length;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement