Notice
Recent Posts
Recent Comments
Link
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[๋ฐฑ์ค€ 3052๋ฒˆ] ๋‚˜๋จธ์ง€ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 3052๋ฒˆ] ๋‚˜๋จธ์ง€ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 1. 17. 01:33
728x90
๋ฐ˜์‘ํ˜•

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

 

3052๋ฒˆ: ๋‚˜๋จธ์ง€

๊ฐ ์ˆ˜๋ฅผ 42๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋Š” 39, 40, 41, 0, 1, 2, 40, 41, 0, 1์ด๋‹ค. ์„œ๋กœ ๋‹ค๋ฅธ ๊ฐ’์€ 6๊ฐœ๊ฐ€ ์žˆ๋‹ค.

www.acmicpc.net

 

const fs = require('fs');
let input = fs
  .readFileSync('/dev/stdin')
  .toString()
  .trim()
  .split('\n')
  .map((v) => +v);

const map = new Map();

input.filter((value) => {
  map.set(value % 42);
});

console.log(map.size);

 

input => ๊ฐœํ–‰๋˜์–ด ์ž…๋ ฅ๋œ ๊ฐ’๋“ค์„ ๋ฐฐ์—ด์— ๋„ฃ์Œ (๋ฌธ์ž๋กœ ๋ณ€ํ™˜ => ์–‘์˜† ๊ณต๋ฐฑ ์ œ๊ฑฐ => ๊ฐœํ–‰์„ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์—ด ์ •์˜ => ๋ฌธ์ž๋ฅผ ์ˆซ์ž๋กœ)

 

map์„ ์ •์˜ํ•ด ๋‚˜๋ˆˆ ๊ฐ’๋“ค์„ ๋„ฃ๊ณ , map ์‚ฌ์ด์ฆˆ๋ฅผ ๋ฆฌํ„ดํ•จ.

(map์€ ์ค‘๋ณต๋œ ๊ฐ’์ด ๋“ค์–ด๊ฐˆ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ!)

728x90
๋ฐ˜์‘ํ˜•
Comments