알고리즘/SW Expert Academy

[D4] 8382. 방향 전환

혬혬 2019. 10. 6. 11:13
728x90
#include <stdio.h>
int start_x = 0;
int start_y = 0;
int end_x = 0;
int end_y = 0;
int virtual_reality(int signal,int amount,int x, int y) {
	if (x == end_x&&end_y == y)
		return amount;
	if (signal == 0) {
		if (x > end_x) 
			return virtual_reality(1, amount + 1, x - 1, y);
		else
			return virtual_reality(1, amount + 1, x + 1, y);
	}
	else {
		if (y > end_y)
			return virtual_reality(0, amount + 1, x, y-1);
		else
			return virtual_reality(0, amount + 1, x, y+1);	
	}

}

int main() {

	int test_case = 0;
	scanf("%d", &test_case);
	char buffer = 0;
	scanf("%c", &buffer);
	for (int q = 0; q < test_case; q++) {
		scanf("%d %d %d %d", &start_x, &start_y, &end_x, &end_y);
		int signal = 0;
		int box = virtual_reality(0, 0, start_x, start_y);
		int box2= virtual_reality(1, 0, start_x, start_y);
		if (box2 > box)
			printf("#%d %d\n", q + 1, box);
		else
			printf("#%d %d\n", q + 1, box2);
	}

	return 0;
}
728x90