Skip to content

Commit ba20895

Browse files
committed
구름 코테 연습 & nodejs input 케이스 구현
1 parent 8e6e635 commit ba20895

6 files changed

Lines changed: 223 additions & 0 deletions

File tree

src/grap3fruit/goorm/43089.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Run by Node.js
2+
const getResultLength = (data) => {
3+
dataArr = data[0].split('');
4+
// console.log(dataArr)
5+
const result = dataArr.filter((el) => el === data[1]);
6+
return result.length;
7+
};
8+
9+
const readline = require('readline');
10+
const rl = readline.createInterface({
11+
input: process.stdin,
12+
output: process.stdout,
13+
});
14+
15+
let count = 0;
16+
let n = 2;
17+
data = [];
18+
rl.on('line', function (line) {
19+
data.push(line);
20+
count += 1;
21+
if (count === n) {
22+
rl.close();
23+
}
24+
}).on('close', function () {
25+
console.log(getResultLength(data));
26+
process.exit();
27+
});

src/grap3fruit/goorm/43125.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Run by Node.js
2+
3+
const readline = require('readline');
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
});
8+
9+
let N = 0;
10+
// const data = [];
11+
let count = 0;
12+
13+
rl.on('line', function (line) {
14+
if (!N) {
15+
N = +line;
16+
} else {
17+
const data = line.split(' ').map((el) => +el);
18+
let min = data[0];
19+
for (let i = 1; i < data.length; i++) {
20+
if (data[i] < min) {
21+
min = data[i];
22+
}
23+
}
24+
console.log(min);
25+
rl.close();
26+
}
27+
}).on('close', function () {
28+
process.exit();
29+
});

src/grap3fruit/goorm/88520.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const print = (data) => {
2+
console.log(data);
3+
};
4+
5+
const getTrashCount = (data, A, B, K) => {
6+
let count = 0;
7+
for (let i = A; i < A + K; i++) {
8+
for (let j = B; j < B + K; j++) {
9+
if (data[i][j] === 1) {
10+
count += 1;
11+
}
12+
}
13+
}
14+
return count;
15+
};
16+
17+
const solution = (data, info) => {
18+
const [N, K] = info;
19+
let min_result = K * K;
20+
for (let i = 0; i < N - K + 1; i++) {
21+
for (let j = 0; j < N - K + 1; j++) {
22+
min_result = Math.min(min_result, getTrashCount(data, i, j, K));
23+
}
24+
}
25+
console.log(min_result);
26+
};
27+
28+
const readline = require('readline');
29+
30+
(async () => {
31+
let rl = readline.createInterface({ input: process.stdin });
32+
33+
let T = null;
34+
let info = null; // N, K
35+
let data = [];
36+
let count_T = 0;
37+
let count_N = 0;
38+
for await (const line of rl) {
39+
if (!T) {
40+
T = +line;
41+
} else if (T && !info) {
42+
info = line.split(' ').map((el) => +el);
43+
} else {
44+
data.push(line.split(' ').map((el) => +el));
45+
count_N += 1;
46+
}
47+
if (T && info) {
48+
if (info[0] === count_N) {
49+
// 로직 수행 & 초기화
50+
print(data);
51+
solution(data, info);
52+
53+
info = null; // N, K
54+
data = [];
55+
count_T = 0;
56+
count_N = 0;
57+
}
58+
}
59+
}
60+
61+
// rl.close();
62+
63+
process.exit();
64+
})();

src/grap3fruit/goorm/input.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const print = (N, data) => {
2+
console.log(N);
3+
console.log(data);
4+
};
5+
6+
const readline = require('readline');
7+
const rl = readline.createInterface({
8+
input: process.stdin,
9+
output: process.stdout,
10+
});
11+
12+
let N = null;
13+
let count = 0;
14+
const data = [];
15+
16+
rl.on('line', function (line) {
17+
console.log(line);
18+
if (!N) {
19+
N = +line;
20+
} else {
21+
// data.push(line.split(' ').map((el) => +el));
22+
// data.push(line.split('').map((el) => +el));
23+
// data.push(line.split('').map((el) => el));
24+
data.push(line);
25+
}
26+
count += 1;
27+
if (count === N) {
28+
rl.close();
29+
}
30+
}).on('close', function () {
31+
print(N, data);
32+
process.exit();
33+
});

src/grap3fruit/goorm/input1_2.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const print = (N, info, data) => {
2+
console.log(N);
3+
console.log(info);
4+
console.log(data);
5+
};
6+
7+
const readline = require('readline');
8+
const rl = readline.createInterface({
9+
input: process.stdin,
10+
output: process.stdout,
11+
});
12+
13+
let N = null;
14+
let info = null;
15+
let count = 0;
16+
const data = [];
17+
18+
rl.on('line', function (line) {
19+
console.log(line);
20+
if (!N) {
21+
N = +line;
22+
} else if (N && !info) {
23+
info = line.split(' ').map((el) => +el);
24+
} else {
25+
data.push(line.split(' ').map((el) => +el));
26+
// data.push(line.split('').map((el) => +el));
27+
// data.push(line.split('').map((el) => el));
28+
// data.push(line);
29+
count += 1;
30+
}
31+
if (count === N) {
32+
rl.close();
33+
}
34+
}).on('close', function () {
35+
print(N, info, data);
36+
process.exit();
37+
});

src/grap3fruit/goorm/input2.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const print = (N, data) => {
2+
console.log(N);
3+
console.log(data);
4+
};
5+
6+
const readline = require('readline');
7+
8+
(async () => {
9+
let rl = readline.createInterface({ input: process.stdin });
10+
let N = null;
11+
let count = 0;
12+
const data = [];
13+
14+
for await (const line of rl) {
15+
if (!N) {
16+
N = +line;
17+
} else {
18+
data.push(line.split('').map((el) => +el));
19+
// data.push(line);
20+
count += 1;
21+
}
22+
if (N === count) {
23+
rl.close();
24+
}
25+
}
26+
27+
data.forEach((el) => {
28+
console.log('len: ', el.length);
29+
});
30+
31+
print(N, data);
32+
process.exit();
33+
})();

0 commit comments

Comments
 (0)