umilove98의 블로그

백준 8437 Java 본문

algorithm/백준

백준 8437 Java

umilove98 2021. 7. 17. 20:04
반응형

klaudia 와 natalia 두 사람이 가지고 있는 사과의 합 , 각각 가지고 있는 사과의 수의 차를 순서대로 입력받고 각자 가지고 있는 사과의 수를 계산하여 출력한다. klaudia가 가진 사과의 수가 diff 개 더 많다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        BigInteger total = new BigInteger(bf.readLine());
        BigInteger diff = new BigInteger(bf.readLine());
        BigInteger two = new BigInteger("2");
        
        BigInteger klaudia = (total.subtract(diff)).divide(two).add(diff); //(total-diff)/2+diff
        BigInteger natalia = (total.subtract(diff)).divide(two); //(total-diff)/2
        
        System.out.println(klaudia);
        System.out.println(natalia);
 
    }
 
}
cs
 
반응형

'algorithm > 백준' 카테고리의 다른 글

백준 11654 Java  (0) 2021.07.17
백준 10430 Python  (0) 2021.07.17
백준 8370 Java  (0) 2021.07.17
백준 6749 Java  (0) 2021.07.17
백준 5554 Java  (0) 2021.07.17