문제 링크: https://www.acmicpc.net/problem/19532

 

19532번: 수학은 비대면강의입니다

정수 $a$, $b$, $c$, $d$, $e$, $f$가 공백으로 구분되어 차례대로 주어진다. ($-999 \leq a,b,c,d,e,f \leq 999$) 문제에서 언급한 방정식을 만족하는 $\left(x,y\right)$가 유일하게 존재하고, 이 때 $x$와 $y$가 각각 $-

www.acmicpc.net

 

 

단순한 브루트 포스 문제이다. ax+by=c 와 dx+ey=f를 만족하는 x,y를 반복문을 통해서 모든 경우의 수를 탐색해주면 된다.

 

import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
int a,b,c,e,d,f;
a= Integer.parseInt(s[0]);
b= Integer.parseInt(s[1]);
c= Integer.parseInt(s[2]);
d= Integer.parseInt(s[3]);
e= Integer.parseInt(s[4]);
f= Integer.parseInt(s[5]);
int answerX=0;
int answerY=0;
for(int i=-999; i<1000; i++){
for(int j=-999; j<1000; j++){
if((a*i+b*j==c)&&(d*i+e*j==f)){
answerX=i;
answerY=j;
break;
}
}
}
System.out.println(answerX +" "+answerY);
}
}