-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from eric-hjh/main
[황장현] 85차 라이브 코테 제출
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
]) | ||
); |