백준 19532 c++

magicdrill·2024년 4월 13일

백준 문제풀이

목록 보기
300/675

백준 19532 c++

#include <iostream>

using namespace std;

int input(int lower, int upper);
void equation(int* x, int* y, int a, int b, int c, int d, int e, int f);

int main(void)
{
	int a, b, c, d, e, f;
	int x, y;

	a = input(-999, 999);
	b = input(-999, 999);
	c = input(-999, 999);
	d = input(-999, 999);
	e = input(-999, 999);
	f = input(-999, 999);
	equation(&x, &y, a, b, c, d, e, f);
	cout << x << " " << y << endl;

	return 0;
}

int input(int lower, int upper)
{
	int A;

	while (1)
	{
		cin >> A;
		if (A >= lower && A <= upper)
		{
			break;
		}
		else
		{
			;
		}
	}

	return A;
}

void equation(int* x, int*y, int a, int b, int c, int d, int e, int f)
{
	int i, j;
	for (i = -999; i <= 999; i++)
	{
		for (j = -999; j <= 999; j++)
		{
			if (a * i + b * j == c && d * i + e * j == f)
			{
				*x = i;
				*y = j;
				return;
			}
			else
			{
				;
			}
		}
	}

	return;
}

0개의 댓글