Skip to content

Commit d55be47

Browse files
authored
Merge pull request #596 from eric-hjh/main
[황장현] 85차 라이브 코테 제출
2 parents f1700ce + 0aadd19 commit d55be47

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

live8/test85/문제1/황장현.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 T = input[0];
10+
let index = 1;
11+
const result = [];
12+
for (let i = 0; i < T; i++) {
13+
const N = input[index];
14+
const X = input[index + 1].sort((a, b) => a - b);
15+
index += 2;
16+
17+
const XSet = new Set(X);
18+
19+
let count = 0;
20+
for (let p1 = 0; p1 < N - 2; p1++) {
21+
for (let p2 = p1 + 2; p2 < N; p2++) {
22+
const mid = (X[p1] + X[p2]) / 2;
23+
if (Number.isInteger(mid) && XSet.has(mid)) {
24+
count++;
25+
}
26+
}
27+
}
28+
29+
result.push(count);
30+
}
31+
return result.join('\n');
32+
}
33+
34+
console.log(solution(input));

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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(' '));
7+
8+
function solution(input) {
9+
const T = Number(input[0][0]);
10+
let index = 1;
11+
const result = [];
12+
const dx = [-1, 1, 0, 0];
13+
const dy = [0, 0, -1, 1];
14+
15+
for (let i = 0; i < T; i++) {
16+
const [H, W] = input[index].map((el) => Number(el));
17+
const sheeps = input
18+
.slice(index + 1, index + 1 + H)
19+
.map((row) => row.join('').split(''));
20+
21+
index += H + 1;
22+
23+
let count = 0;
24+
function dfs(x, y) {
25+
sheeps[x][y] = '.';
26+
for (let i = 0; i < 4; i++) {
27+
const nx = x + dx[i];
28+
const ny = y + dy[i];
29+
if (nx >= 0 && nx < H && ny >= 0 && ny < W && sheeps[nx][ny] === '#') {
30+
dfs(nx, ny);
31+
}
32+
}
33+
}
34+
35+
for (let i = 0; i < H; i++) {
36+
for (let j = 0; j < W; j++) {
37+
if (sheeps[i][j] === '#') {
38+
count++;
39+
dfs(i, j);
40+
}
41+
}
42+
}
43+
result.push(count);
44+
}
45+
return result.join('\n');
46+
}
47+
48+
console.log(solution(input));

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function solution(clothes) {
2+
let answer = 1;
3+
const dic = {};
4+
5+
for (let i = 0; i < clothes.length; i++) {
6+
const kind = clothes[i][1];
7+
if (dic[kind] !== undefined) {
8+
dic[kind] += 1;
9+
} else {
10+
dic[kind] = 1;
11+
}
12+
}
13+
14+
for (let k in dic) {
15+
answer *= dic[k] + 1;
16+
}
17+
18+
answer -= 1;
19+
return answer;
20+
}
21+
22+
console.log(
23+
solution([
24+
['yellow_hat', 'headgear'],
25+
['blue_sunglasses', 'eyewear'],
26+
['green_turban', 'headgear'],
27+
])
28+
);

0 commit comments

Comments
 (0)