Skip to content

Commit d77d0a1

Browse files
author
Eric
committed
85차 1번 문제풀이
1 parent 1e08fc9 commit d77d0a1

1 file changed

Lines changed: 34 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));

0 commit comments

Comments
 (0)