java

백준 19532 수학은 비대면강의입니다. 자바 java

MiaCoder 2024. 1. 16. 11:27

import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        // 배열 A와 숫자 n을 입력받는다.

        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();
        
        int x = 0;
        int y = 0;

        for (int i = -999; i <= 999; i++) {
        	// 이중 for문을 사용하여 x, y가 -999인 상황부터 999인상황까지 모든 경의우수를 대입한다
            for (int j = -999; j <= 999; j++) {
                if (((a * i) + (b * j) == c) && ((d * i) + (e * j) == f)) {
                    x = i;
                    y = j;
                }
            }
        }
        System.out.print(x + " " + y);
        sc.close();
    }
}

아이디어 :

 

1. 입력 가능한 모든 경의의수를 대입하여 조건을 만족하도록 한다.