Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
837 B
2
Indexable
Never
#include <stdio.h>
#include <math.h>
#include <string.h>

unsigned long long f(unsigned long long x1, unsigned long long y1, unsigned long long x2, unsigned long long y2) {
	unsigned long long count = 0;
	while (1) {
		if (y1 == 0) {
			y1 = x1 + 1;
			x1 = 0;
			if (x1 == x2 && y1 == y2) {
				count++;
				break;
			}
			count++;
		}
		else {
			x1++;
			y1--;
			if (x1 == x2 && y1 == y2) {
				count++;
				break;
			}
			count++;
		}
	}
	return count;
}


void main() {
	unsigned long long n;
	scanf("%llu", &n);
	unsigned long long x1, y1, x2, y2;
	for (unsigned long long i = 0; i < n; i++) {
		scanf("%llu %llu %llu %llu", &x1, &y1, &x2, &y2);
		if (i == 0) {
			printf("Case 1: %llu", f(x1, y1, x2, y2));
		}
		else {
			printf("\nCase %llu: %llu", i + 1, f(x1, y1, x2, y2));
		}
	}
}