본문 바로가기

Algorithm/Baekjoon

[백준_JAVA_알고리즘] 19532 수학은 비대면강의입니다

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
    	
    	int a = scanner.nextInt(); int b = scanner.nextInt(); int c = scanner.nextInt();
    	int d = scanner.nextInt(); int e = scanner.nextInt(); int f = scanner.nextInt();

    	for(int x = -999; x <= 999; x++) {
    		for(int y = -999; y <= 999; y++) {
    			if((a*x+b*y==c) && (d*x+e*y==f)){
					System.out.print(x+" "+y);
					break;
    			}
    		}
    	}
    }
}

 

브루트 포스 알고리즘이다.

for문과 if문을 이용하여 모든 경우의 수를 판별한다.