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

(JAVA) 백준 알고리즘 15552문제 - 빠른 A+B (for문)

by Love of fate 2020. 10. 7.
728x90
반응형

(37분)

* br.readLine().trim()으로 하면 int형을 제대로 받을 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
 
public class Main15552 {
 
    public static void main(String[] args) throws IOException {
        
        
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        int n = Integer.parseInt(br.readLine().trim());
//        
//        for (int i=0; i < n; i++) {
//            String text = br.readLine();
//            String[] word = text.split(" ");
//            int a = Integer.parseInt(word[0]);
//            int b = Integer.parseInt(word[1]);
//            bw.write((a+b) + "\n");
//        }
//        
//        bw.flush();
//        bw.close();
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        char testSu = br.readLine().charAt(0);
        int testCase = Integer.parseInt(String.valueOf(testSu));
    
        for(int i=0; i < testCase; i++) {
            String [] su = br.readLine().split(" ");
            int a = Integer.parseInt(su[0]);
            int b = Integer.parseInt(su[1]);
            bw.write((a+b) + "\n");
        }
        bw.flush();
        bw.close();
    }
}
728x90
반응형