[백준10950_자바스크립트(javascript)] - A+B - 3

경이·2024년 8월 9일

𝑩𝑶𝑱 (𝒋𝒔)

목록 보기
115/325

🔴 문제

A+B - 3


🟡 Sol

const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'Wiki\\input.txt';
const [_, ...inputs] = fs.readFileSync(path).toString().trim().split('\r\n');

for (const input of inputs) {
  const [a, b] = input.split(' ').map(Number);
  console.log(a + b);
}

🟢 풀이

⏰ 소요한 시간 : -

테스트 케이스 개수인 첫 요소를 제외하고 나머지 테스트 케이스를 ...inputs으로 받아왔고 for ... of 문을 사용해 배열 요소를 순회해줬다.
각 요소는 1 1 이런식의 문자열이기 때문에 공백으로 split(' ') 처리해 배열로 바꿔주었고 map 함수를 사용해 각 요소를 숫자로 변경해서 구조 분해 할당해주었다.


🔵 Ref

profile
록타르오가르

0개의 댓글