본문 바로가기
PS/백준

백준 - 수학은 비대면 강의입니다.

by 종안이 2023. 11. 5.

 

 

브루트포스와 관련된 문제다 , 각각의 변수에 -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);
                }
            }
        }
    }
}

댓글