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

[백준] 7891: Can you add this? / Node.js (JavaScript)

by fluss 2023. 4. 27.

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

 

7891번: Can you add this?

The input contains several test cases. The first line contains and integer t (t ≤ 100) denoting the number of test cases. Then t tests follow, each of them consisiting of two space separated integers x and y (−109 ≤ x, y ≤ 109).

www.acmicpc.net

 

문제

Given two integers, calculate and output their sum.

 

입력

The input contains several test cases. The first line contains and integer t (t ≤ 100) denoting the number of test cases. Then t tests follow, each of them consisiting of two space separated integers x and y (−109 ≤ x, y ≤ 109).

 

출력

For each test case output output the sum of the corresponding integers.

 

예제 입력 1

4
-100 100
2 3
0 110101
-1000000000 1

 

예제 출력 1

0
5
110101
-999999999

 

코드

const input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n');
const n = Number(input[0]);
const result = [];
for(let i = 1; i <= n; i++){
    const [x, y] = input[i].split(' ').map(Number);
    result.push(x + y);
}
console.log(result.join('\n'));

댓글