fork download
  1. /// Author: Nguyen Thanh Phong - ti25phong_nt
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define el cout << "\n";
  6. #define FOR(i, start, end, step) for(int i=start; i<=end; i+=step)
  7. #define FORD(i, end, start, step) for(int i=end; i>=start; i-=step)
  8. #define fi first
  9. #define se second
  10. #define pb push_back
  11. #define pf push_front
  12. #define popb pop_back()
  13. #define popf pop_front()
  14. #define ALL(x) (x).begin(),(x).end()
  15. #define ElfariaAlbisSerfort int main()
  16.  
  17. typedef long long ll;
  18. typedef unsigned long long ull;
  19. typedef vector<int> vi;
  20. typedef vector<ll> vll;
  21. typedef pair<int, int> pii;
  22. typedef pair<ll, ll> pll;
  23.  
  24. const int NN = 1e6 + 5;
  25. const int INF = 0x3f3f3f3f;
  26. const long long LINF = 1e18 + 7;
  27. const int base = 31;
  28. const long long MOD = 1e9 + 7;
  29. const int d4x[] = {0, 0, -1, 1};
  30. const int d4y[] = {-1, 1, 0, 0};
  31. const int d8x[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  32. const int d8y[] = {-1, 0, 1, -1, 1, -1, 0, 1};
  33.  
  34. /// ------------------ GLOBAL VARIABLE ------------------
  35. ll a1, a2, b1, b2;
  36.  
  37. /// ------------------ MAIN PROGRAMME -------------------
  38. ElfariaAlbisSerfort{
  39. #define NAME "paint"
  40. if(fopen(NAME".inp","r")){
  41. freopen(NAME".inp", "r", stdin);
  42. freopen(NAME".out", "w", stdout);
  43. }
  44.  
  45. ios_base :: sync_with_stdio(false);
  46. cin.tie(0); cout.tie(0);
  47.  
  48. cin >> a1 >> a2 >> b1 >> b2;
  49. if(a1 > a2) swap(a1, a2);
  50. if(b1 > b2) swap(b1, b2);
  51. if(a1<b1 && a2>b2){
  52. cout << a2 - a1;
  53. }
  54. else if(b1<a1 && b2>a2){
  55. cout << b2 - b1;
  56. }
  57. else if(a1==b1 && a2==b2){
  58. cout << a2 - b2;
  59. }
  60. else if(a1<=b1 && a2>=b1 && a2<=b2){
  61. cout << b2 - a1;
  62. }
  63. else if(b1<=a1 && b2>=a1 && b2<=a2){
  64. cout << a2 - b1;
  65. }
  66. else{
  67. cout << a2-a1 + b2-b1;
  68. }
  69.  
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty