
브루트포스와 관련된 문제다 , 각각의 변수에 -999부터 999까지의 모든 값을 집어넣어 주면서 확인해보면 조건을 충족하는 값을 구할 수 있다. 브루트 포스 연습에 괜찮은 문제라고 생각된다,
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
List<Integer> array = new ArrayList<>();
String s = bf.readLine();
String[] split = s.split(" ");
int a = Integer.parseInt(split[0]);
int b = Integer.parseInt(split[1]);
int c = Integer.parseInt(split[2]);
int d = Integer.parseInt(split[3]);
int e = Integer.parseInt(split[4]);
int f = Integer.parseInt(split[5]);
for (int i = -999; i <= 999; i++) {
for (int j = -999; j <= 999; j++) {
if (a * i + b * j == c && d * i + e * j == f) {
System.out.println(i + " " + j);
}
}
}
}
}
'PS > 백준' 카테고리의 다른 글
백준 - 과제 안 내신 분..? ( 5597번 ) (0) | 2023.11.06 |
---|---|
백준 - 나머지 (3052번) (0) | 2023.11.05 |
백준 - 상수 (2908번) (0) | 2023.11.04 |
백준 - 문자열 반복 (2675번) (0) | 2023.10.29 |
백준 - 알고리즘 수업 - 알고리즘의 수행 시간 6 (0) | 2023.10.28 |
댓글