Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jiho/Day20/백준_BFS_단지번호붙이기.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ answer.forEach((item) => console.log(item));
2. 2차원 배열 bfs (정형화된 패턴)
dx dy로 방향 배열을 선언하고,
nrow, ncol을 만드는 식으로 작성
*/
*/
45 changes: 45 additions & 0 deletions Jiho/Day22/백준_10845.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require("fs");
const input = fs
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "../input.txt")
.toString()
.trim()
.split("\n");

const N = Number(input[0]);

let arr = [];
let i;
let answer = [];
for (i = 1; i <= N; i++) {
let cmd = input[i].trim().split(" ");
switch (cmd[0]) {
case "push":
arr.push(parseInt(cmd[1]));
break;
case "pop":
if (arr.length === 0) answer.push(-1);
else {
const val = arr.shift();
answer.push(val);
}
break;
case "size":
answer.push(arr.length);
break;
case "empty":
if (arr.length) {
answer.push(0);
} else {
answer.push(1);
}
break;
case "front":
arr.length === 0 ? answer.push(-1) : answer.push(arr[0]);
break;
case "back":
arr.length === 0 ? answer.push(-1) : answer.push(arr[arr.length - 1]);
break;
}
}

console.log(answer.join("\n"));
41 changes: 41 additions & 0 deletions Jiho/Day22/백준_11724.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const fs = require("fs");
const input = fs
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "../input.txt")
.toString()
.trim()
.split("\n");

const [N, M] = input.shift().split(" ").map(Number);
let graph = [...Array(N + 1)].map(() => []);
const visited = new Array(N + 1).fill(false);
const arr = input.map((v) => v.split(" ").map(Number));
// # 입력 처리

// 양방향(무방향) 그래프로 만들기
arr.forEach(([from, to]) => {
graph[from].push(to);
graph[to].push(from);
});

const BFS_FindConnected = (node) => {
const queue = [node];
visited[node] = true;
while (queue.length) {
const val = queue.shift();
for (const n of graph[val]) {
if (!visited[n]) {
visited[n] = true;
queue.push(n);
}
}
}
};

let answer = 0;
for (i = 1; i <= N; i++) {
if (!visited[i]) {
answer++;
BFS_FindConnected(i);
}
}
console.log(answer);
17 changes: 17 additions & 0 deletions Jiho/Day22/백준_5585.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require("fs");
const input = fs
.readFileSync(process.platform === "linux" ? "/dev/stdin" : "../input.txt")
.toString()
.trim();

let money = 1000 - parseInt(input);

let answer = 0;
const costs = [500, 100, 50, 10, 5, 1];
for (const cost of costs) {
const cnt = Math.floor(money / cost);
answer += cnt;
money -= cost * cnt;
}

console.log(answer);