Min and maximum number of movement to line the three integers consecutive.


My 1st Correct Code

#include <iostream>
#define max(x,y) x > y? x : y
int main() {
	int l, m, r;
	int ans_m, ans_M;
	std::cin >> l >> m >> r;

	int caseL = m - l - 1;
	int caseR = r - m - 1;
	if (caseL == 0 && caseR == 0) {
		ans_m = ans_M = 0;
	}
	else if (caseL == 1 || caseR == 1) {
		ans_m = 1;
		ans_M = max(caseL, caseR);
	}
	else {
		ans_m = 2;
		ans_M = max(caseL, caseR);
	}

	std::cout << ans_m << "\n" << ans_M;

	return 0;
}


comments

2020-01-17 Yay! Check the input and output before submitting to site..