Skip to content

Commit da98c52

Browse files
Merge pull request #588 from eric-hjh/main
[황장현] 81차 라이브 코테 제출
2 parents a56773d + cba0b70 commit da98c52

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

live8/test81/문제1/황장현.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const [N, M, V] = input[0];
10+
const graph = Array.from(Array(N + 1), () => Array(N + 1).fill(0));
11+
12+
for (let i = 1; i <= M; i++) {
13+
let [row, column] = input[i];
14+
graph[row][column] = 1;
15+
graph[column][row] = 1;
16+
}
17+
18+
const visited = new Array(N + 1).fill(false);
19+
const dfs_answer = [];
20+
const bfs_answer = [];
21+
22+
function dfs(V) {
23+
visited[V] = true;
24+
dfs_answer.push(V);
25+
for (let i = 1; i < graph.length; i++) {
26+
if (graph[V][i] === 1 && !visited[i]) {
27+
dfs(i);
28+
}
29+
}
30+
}
31+
32+
function bfs(V) {
33+
const queue = [];
34+
visited[V] = true;
35+
bfs_answer.push(V);
36+
queue.push(V);
37+
38+
while (queue.length !== 0) {
39+
let dequeue = queue.shift();
40+
for (let i = 1; i < graph.length; i++) {
41+
if (graph[dequeue][i] === 1 && !visited[i]) {
42+
visited[i] = true;
43+
queue.push(i);
44+
bfs_answer.push(i);
45+
}
46+
}
47+
}
48+
}
49+
50+
dfs(V);
51+
visited.fill(false);
52+
bfs(V);
53+
54+
console.log(dfs_answer.join(' '));
55+
console.log(bfs_answer.join(' '));
56+
}
57+
58+
solution(input);

live8/test81/문제2/황장현.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const N = input[0][0];
10+
const M = input[1][0];
11+
const computerList = input.slice(2);
12+
13+
const graph = Array.from({ length: N + 1 }, () => []);
14+
const visited = Array.from({ length: N + 1 }).fill(false);
15+
16+
for (let [c1, c2] of computerList) {
17+
graph[c1].push(c2);
18+
graph[c2].push(c1);
19+
}
20+
let count = 0;
21+
22+
function dfs(node) {
23+
count++;
24+
visited[node] = true;
25+
const list = graph[node];
26+
for (let i = 0; i < list.length; i++) {
27+
if (!visited[list[i]]) dfs(list[i]);
28+
}
29+
}
30+
dfs(1);
31+
return count - 1;
32+
}
33+
34+
console.log(solution(input));

live8/test81/문제3/황장현.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function solution(record) {
2+
const userInfo = {};
3+
const action = [];
4+
const stateMapping = {
5+
Enter: '님이 들어왔습니다.',
6+
Leave: '님이 나갔습니다.',
7+
};
8+
9+
record.forEach((v) => {
10+
const [state, id, nick] = v.split(' ');
11+
12+
if (state !== 'Change') {
13+
action.push([state, id]);
14+
}
15+
16+
if (nick) {
17+
userInfo[id] = nick;
18+
}
19+
});
20+
console.log(userInfo);
21+
22+
return action.map(([state, uid]) => {
23+
return `${userInfo[uid]}${stateMapping[state]}`;
24+
});
25+
}
26+
console.log(
27+
solution([
28+
'Enter uid1234 Muzi',
29+
'Enter uid4567 Prodo',
30+
'Leave uid1234',
31+
'Enter uid1234 Prodo',
32+
'Change uid4567 Ryan',
33+
])
34+
);
35+
36+
const obj = {};
37+
obj['asdf'] = '1';
38+
console.log(obj.asdf);

0 commit comments

Comments
 (0)