뻠삥

https://www.acmicpc.net/problem/10950

 

10950번: A+B - 3

두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

덧셈 알고리즘입니다.

첫 번째 입력으로 루프 횟수를 입력받고, 주어진 횟수만큼 덧셈 및 출력을 반복합니다.

풀이는 아래와 같습니다.

 

1. Java

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
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) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        try {
            int cntLoop = Integer.parseInt(br.readLine());
            
            for (int i = 0; i < cntLoop; i++) {
                String[] nums = br.readLine().split(" "-1);
                String str = String.valueOf((Integer.parseInt(nums[0]) + Integer.parseInt(nums[1]))) + "\n";
                bw.write(str);
            }
            
            br.close();
            bw.close();
            
        } catch (Exception e) {
            
        }
    }
}
 
cs

 

2. Python

1
2
3
4
5
if __name__ == '__main__':
    cntLoop = int(input())
    for i in range(0, cntLoop):
        num1, num2 = map(int, input().split())
        print(num1 + num2)
cs