본문 바로가기

알고리즘 (with. 백준 문제풀이)9

백준 25192번 [인사성 밝은 곰곰이] const input = require('fs') .readFileSync('/dev/stdin') .toString() .trim() .split('\n') const [n, ...test] = input const hashSet = new Set(); let answer = 0; test.map((str) => { if(str == "ENTER"){ answer += hashSet.size hashSet.clear() } else{ hashSet.add(str); } }) answer += hashSet.size console.log(answer) 문자열과 나온 횟수를 map으로 풀려고 시도하다가 set으로 접근하니까 쉽게 풀렸던 문제 2023. 9. 21.
백준 17219번 [비밀번호 찾기] const input = require('fs') .readFileSync('/dev/stdin') .toString() .trim() .split('\n') const [n, m] = input.shift().split(' ') const map = new Map() for(let i=0; i 2023. 9. 19.
백준 1966번 [프린터 큐] const fs = require('fs'); const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); let [n, ...testcases] = input; // let [n, m] = [4, 2] // const priQ = [1, 3, 2, 4] for (let i = 0; i < n; i++) { let m = Number(testcases[i * 2].split(' ')[1]) let priQ = testcases[i * 2 + 1].split(' ').map(Number); let answer = 0; while (true) { let e1 = priQ.shift() if (e1 < Math.max(...priQ)) .. 2023. 9. 19.
백준 2161번 [카드1] const fs = require('fs'); const input = fs.readFileSync('/dev/stdin').toString().trim().split(); const n = Number(input[0]); let arr = Array.from(new Array(n), (x, i) => i+1); let answer = []; while(arr.length > 0){ answer.push(arr.shift()); if (arr.length > 0) { arr.push(arr.shift()); } } str = answer.join(" ") console.log(str) 2023. 9. 18.