Skip to content

Commit

Permalink
Merge pull request #596 from eric-hjh/main
Browse files Browse the repository at this point in the history
[황장현] 85차 라이브 코테 제출
  • Loading branch information
eric-hjh authored Feb 28, 2025
2 parents f1700ce + 0aadd19 commit d55be47
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
34 changes: 34 additions & 0 deletions live8/test85/문제1/황장현.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const input = require('fs')
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
.toString()
.trim()
.split('\n')
.map((el) => el.split(' ').map(Number));

function solution(input) {
const T = input[0];
let index = 1;
const result = [];
for (let i = 0; i < T; i++) {
const N = input[index];
const X = input[index + 1].sort((a, b) => a - b);
index += 2;

const XSet = new Set(X);

let count = 0;
for (let p1 = 0; p1 < N - 2; p1++) {
for (let p2 = p1 + 2; p2 < N; p2++) {
const mid = (X[p1] + X[p2]) / 2;
if (Number.isInteger(mid) && XSet.has(mid)) {
count++;
}
}
}

result.push(count);
}
return result.join('\n');
}

console.log(solution(input));
48 changes: 48 additions & 0 deletions live8/test85/문제2/황장현.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const input = require('fs')
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
.toString()
.trim()
.split('\n')
.map((el) => el.split(' '));

function solution(input) {
const T = Number(input[0][0]);
let index = 1;
const result = [];
const dx = [-1, 1, 0, 0];
const dy = [0, 0, -1, 1];

for (let i = 0; i < T; i++) {
const [H, W] = input[index].map((el) => Number(el));
const sheeps = input
.slice(index + 1, index + 1 + H)
.map((row) => row.join('').split(''));

index += H + 1;

let count = 0;
function dfs(x, y) {
sheeps[x][y] = '.';
for (let i = 0; i < 4; i++) {
const nx = x + dx[i];
const ny = y + dy[i];
if (nx >= 0 && nx < H && ny >= 0 && ny < W && sheeps[nx][ny] === '#') {
dfs(nx, ny);
}
}
}

for (let i = 0; i < H; i++) {
for (let j = 0; j < W; j++) {
if (sheeps[i][j] === '#') {
count++;
dfs(i, j);
}
}
}
result.push(count);
}
return result.join('\n');
}

console.log(solution(input));
28 changes: 28 additions & 0 deletions live8/test85/문제3/황장현.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function solution(clothes) {
let answer = 1;
const dic = {};

for (let i = 0; i < clothes.length; i++) {
const kind = clothes[i][1];
if (dic[kind] !== undefined) {
dic[kind] += 1;
} else {
dic[kind] = 1;
}
}

for (let k in dic) {
answer *= dic[k] + 1;
}

answer -= 1;
return answer;
}

console.log(
solution([
['yellow_hat', 'headgear'],
['blue_sunglasses', 'eyewear'],
['green_turban', 'headgear'],
])
);

0 comments on commit d55be47

Please sign in to comment.