Print a single integer giving the minimum distance Farmer John needs to haul manure in his tractor.
My 1st Correct Code
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int a, b, x, y;
int result;
scanf("%d %d %d %d", &a, &b, &x, &y); //0~100. can be same
int d1, d2, d3;
d1 = abs(a - b);
d2 = abs(a - x) + abs(y-b);
d3 = abs(a - y) + abs(x-b);
result = (d1 < d2) ? d1 : d2;
result = (result < d3) ? result : d3;
printf("%d", result);
}
comments
2020-01-17 printf(ā%dā, min(min(abs(a-x) + abs(b-y), abs(b-a)), abs(a-y) + abs(b-x)));
