-
-
Save healtheloper/3c9d7baf9ad5150588b823eea40174cb to your computer and use it in GitHub Desktop.
백준 알고리즘 템플릿
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
// https://www.acmicpc.net/problem/11650 | |
// template2.js | |
const readline = require("readline"); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
const input = []; | |
const solution = (input) => { | |
const [count, ...rest] = input; | |
let dict = rest.map((r) => { | |
const [x, y] = r.split(" "); | |
return { | |
x, | |
y, | |
}; | |
}); | |
dict = dict.sort((a, b) => { | |
if (a.x === b.x) return a.y - b.y; | |
return a.x - b.x; | |
}); | |
dict = dict.map((position) => position.x + " " + position.y); | |
return dict.reduce((prev, next) => prev + "\n" + next); | |
}; | |
rl.on("line", (answer) => { | |
input.push(answer.trim()); | |
}).on("close", () => { | |
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
// https://www.acmicpc.net/problem/1427 | |
// template1.js | |
const readline = require("readline"); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
const solution = (input) => { | |
const arr = input.split("").map((v) => +v); | |
arr.sort((a, b) => b - a); | |
return arr.join(""); | |
}; | |
rl.on("line", (answer) => { | |
console.log(solution(answer)); | |
rl.close(); | |
}); |
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
const readline = require("readline"); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
const solution = (input) => { | |
let answer = 0; | |
return answer; | |
}; | |
rl.on("line", (answer) => { | |
console.log(solution(answer)); | |
rl.close(); | |
}); |
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
const readline = require("readline"); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
const input = []; | |
const solution = (input) => { | |
let answer = 0; | |
const a = "123"; | |
return answer; | |
}; | |
rl.on("line", (answer) => { | |
input.push(answer.trim()); | |
}).on("close", () => { | |
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
// 1. 하나의 값을 입력받을 때 | |
const input = require("fs").readFileSync("/dev/stdin").toString().trim(); | |
// 2. 공백으로 구분된 한 줄의 값들을 입력받을 때 | |
const input = require("fs") | |
.readFileSync("/dev/stdin") | |
.toString() | |
.trim() | |
.split(" "); | |
// 3. 여러 줄의 값들을 입력받을 때 | |
const input = require("fs") | |
.readFileSync("/dev/stdin") | |
.toString() | |
.trim() | |
.split("\n"); | |
// 4. 첫 번째 줄에 자연수 n을 입력받고, 그 다음줄에 공백으로 구분된 n개의 값들을 입력받을 때 | |
const [n, ...arr] = require("fs") | |
.readFileSync("/dev/stdin") | |
.toString() | |
.trim() | |
.split(/\s+/); | |
// 5. 첫 번째 줄에 자연수 n을 입력받고, 그 다음줄부터 n개의 줄에 걸쳐 한 줄에 하나의 값을 입력받을 때 | |
const [n, ...arr] = require("fs") | |
.readFileSync("/dev/stdin") | |
.toString() | |
.trim() | |
.split("\n"); | |
// 6. 하나의 값 또는 공백으로 구분된 여러 값들을 여러 줄에 걸쳐 뒤죽박죽 섞여서 입력받을 때 | |
// ex) n 입력 - 공백으로 구분된 n개의 값 입력 - m 입력 - 여러 줄에 걸쳐 m개의 값 입력 | |
const input = require("fs") | |
.readFileSync("/dev/stdin") | |
.toString() | |
.trim() | |
.split(/\s+/); | |
const n = input[0]; | |
const n_arr = input.slice(1, n + 1); | |
const [m, ...m_arr] = input.slice(n + 1); | |
// 2~6에서 입력받는 값들을 모두 String에서 Number로 바꾸려면 split()뒤에 .map(v => +v)를 추가 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
template2 의 input 은 줄바꿈이 있다면 2중배열로 받아옵니다.