✨JSY
article thumbnail
Published 2023. 9. 12. 15:51
백준 5597 javascript | node.js PS/백준
문제

문제 출처 - https://www.acmicpc.net/problem/5597

 

5597번: 과제 안 내신 분..?

X대학 M교수님은 프로그래밍 수업을 맡고 있다. 교실엔 학생이 30명이 있는데, 학생 명부엔 각 학생별로 1번부터 30번까지 출석번호가 붙어 있다. 교수님이 내준 특별과제를 28명이 제출했는데,

www.acmicpc.net

풀이

자료 구조 hash map 을 만든다.

const map = new Map();

그리고 있는 숫자는 1, 없는 숫자는 0이 되어 0일 때 해당 숫자를 출력하도록 한다.

if (!map.has(i)) console.log(i);	// if 문 조건이 hash map 에 있는 지를 판별해냄

 

코드
const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = fs.readFileSync(filePath).toString().split('\n');

const nums = input.map((item) => +item);
const map = new Map();

for (let i = 0; i < nums.length; i++) {
  map.set(nums[i], 1);
}

for (let i = 1; i <= 30; i++) {
  if (!map.has(i)) console.log(i);
}

'PS > 백준' 카테고리의 다른 글

백준 10811 javascript | node.js  (0) 2023.09.12
백준 3052 javascript | node.js  (0) 2023.09.12
백준 10813 javascript | node.js  (0) 2023.09.12
백준 10810 javascript | node.js  (0) 2023.09.12
백준 10807 javascript | node.js  (0) 2023.09.12
profile

✨JSY

@JUNSANG YOO

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!