반응형



막상 해결하니 그렇게 어려운 문제는 아니었다..
1. Scanner를 이용한 방법
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
int f = sc.nextInt();
for(int x=-999; x<=1000; x++){
for(int y=-999; y<=1000; y++){
if(a*x+b*y == c){
if(d*x+e*y == f){
System.out.println(x + " " + y);
}
}
}
}
sc.close();
}
}
2. BufferedReader를 이용한 방법
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
int f = Integer.parseInt(st.nextToken());
for(int x=-999; x<=1000; x++){
for(int y=-999; y<=1000; y++){
if(a*x+b*y == c){
if(d*x+e*y == f){
System.out.println(x + " " + y);
}
}
}
}
br.close();
}
}반응형
'알고리즘 > 백준' 카테고리의 다른 글
| [백준] 2839 - 설탕 배달 (JAVA/ 자바) (0) | 2024.05.28 |
|---|---|
| [백준] 1436 - 영화감독 숌 (JAVA/ 자바) (0) | 2024.05.14 |
| [백준] 2231 - 분해합 (JAVA/ 자바) (0) | 2024.05.01 |
| [백준] 2798 - 블랙잭 (JAVA/ 자바) (0) | 2024.04.24 |
| [백준] 24313 - <알고리즘 수업> 점근적 표기 1 (JAVA/ 자바) (0) | 2024.04.23 |