문제
3052번: 나머지
각 수를 42로 나눈 나머지는 39, 40, 41, 0, 1, 2, 40, 41, 0, 1이다. 서로 다른 값은 6개가 있다.
www.acmicpc.net
메모
- Set 생성자를 써서 중복 요소를 제거한다.
- trim을 쓰지 않으면 입력 마지막에 개행문자가 추가되어 오답으로 처리된다.
정답
let fs = require("fs");
let filePath = process.platform === "linux" ? "/dev/stdin" : "test.txt";
let remain = fs
.readFileSync(filePath)
.toString()
.trim()
.split("\n")
.map(Number)
.map(x => x % 42);
let answer = [...new Set(remain)];
console.log(parseInt(answer.length));
let fs = require("fs");
let filePath = process.platform === "linux" ? "/dev/stdin" : "test.txt";
let remain = fs
.readFileSync(filePath)
.toString()
.trim()
.split("\n")
.map(Number)
.map(x => x % 42);
let answer = [];
remain.forEach(x => {
if (!answer.includes(x)) answer.push(x);
});
console.log(answer.length);