출력
console.log()
입력
const file = process.platform === 'linux' ? '/dev/stdin' : 'input.txt' // 백준
const fs = require('fs')
const input = fs.readFileSync(file).toString().trim()
- 숫자
+input
Number(input)
parseInt(input)
- 문자
input
- 수열
input.split(' ').map(Number)
- 문자열
input.split(' ')
- 배열 요소만 출력
console.log(...arr)
console.log(arr.join(' ')) // → string type
반복문
// 1
for (let index = 0; index < array.length; index++) {
const element = array[index]
}
// 2
while (condition) {
}
// 3
array.forEach(element => {
})
// 4
for (const key in object) {
if (Object.hasOwnProperty.call(object, key)) {
const element = object[key]
}
}
// 5
for (const iterator of object) {
}
조건문
if (condition) {
} else {
}
[백준BOJ] JavaScript 입력 받는 방법 종류별 정리 - JavaScript(node.js)
아래의 내용은 제가 Javascript로 백준 사이트에서 문제를 풀 때 사용하는 방법을 공유하고자 작성한 글입니다. 개선점에 대한 피드백 언제든 환영입니다!🙆♂️ 입력받는 방법으로 바로 이동
minjo0n.tistory.com
'알고리즘' 카테고리의 다른 글
[알고리즘] 완전탐색(Brute Force) (0) | 2024.04.23 |
---|