본문 바로가기
알고리즘/백준

[백준] 19532 - 수학은 비대면강의입니다. (JAVA/ 자바)

by pandastic 2024. 5. 5.
반응형

19532번 문제(1)
19532번 문제(2)

막상 해결하니 그렇게 어려운 문제는 아니었다..

 

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();
    }
}
반응형