[Java] 백준 1434번 [책 정리] 자바

: ) YOUNG·2021년 11월 2일
2

알고리즘

목록 보기
11/422
post-thumbnail

문제: https://www.acmicpc.net/problem/1434

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
       
        String[] NM = br.readLine().split(" ");
        String[] box = br.readLine().split(" ");
        String[] book = br.readLine().split(" ");

        int N = Integer.parseInt(NM[0]);
        int M = Integer.parseInt(NM[1]);
        int sum_box = 0;
        int sum_book = 0;
      
        for(int i = 0; i < N; i++) {
            sum_box += Integer.parseInt(box[i]);
        }

        for(int i = 0; i < M; i++) {
            sum_book += Integer.parseInt(book[i]);
        }

        int result = sum_box - sum_book;

        System.out.println(result);
        bw.flush();
        bw.close();
    }
}

0개의 댓글