Print three lines of output, giving the final amount of milk in each bucket, after 100 pour operations.


My 1st Correct Code

#include <iostream>

int main() {
	int c[4]; int m[4];
	std::cin >> c[1] >> m[1];
	std::cin >> c[2] >> m[2];
	std::cin >> c[3] >> m[3];

	for (int i = 0; i < 100; i++) {
		int from = i % 3 + 1;
		int to = (i + 1) % 3 + 1;
		int tmp;

		tmp = c[to] - m[to];
		if (m[from] >= tmp) {
			m[to] += tmp; m[from] -= tmp;
		}
		else {
			m[to] += m[from]; m[from] = 0;
		}
	}
	printf("%d\n%d\n%d", m[1], m[2], m[3]);
}


comments

2020-01-16