[백준5597_자바스크립트(javascript)] - 과제 안 내신 분..?

경이·2024년 9월 5일

𝑩𝑶𝑱 (𝒋𝒔)

목록 보기
170/325

🔴 문제

과제 안 내신 분..?


🟡 Sol

const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'Wiki\\input.txt';
const inputs = fs
  .readFileSync(path)
  .toString()
  .trim()
  .split('\n')
  .map(Number)
  .sort((a, b) => a - b);

const students = Array.from({ length: 30 }).fill(true);

for (const input of inputs) {
  students[input - 1] = false;
}

for (let i = 0; i < 30; i++) {
  if (students[i]) console.log(i + 1);
}

🟢 풀이

⏰ 소요한 시간 : -

30칸짜리 배열을 만들어 true로 초기화 한 후, 입력 값을 순회하며 해당 인덱스 - 1false로 초기화한다. 그 후 다시 배열을 순회하며 값이 true인 인덱스만 출력해주면된다.
번호는 1번부터 시작하므로 +1을 해준다.


🔵 Ref

profile
록타르오가르

0개의 댓글