반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- type challenge
- Node.js
- 알고리즘
- 수학
- Nestjs
- dfs
- 프로그래머스 레벨 2
- 쉬운 문제
- 크롤링
- 프로그래머스
- 소켓
- typescript
- javascript
- 백준
- 타입스크립트
- 그래프
- 레벨 1
- 문자열
- 자바스크립트
- 가천대
- Crawling
- 타입 챌린지
- ip
- dp
- Algorithm
- HTTP 완벽 가이드
- socket
- HTTP
- BFS
- TCP
Archives
- Today
- Total
kakasoo
[node.js] 8진수 2진수 ( 백준 1212번 ) 본문
반응형
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", (line) => {
main(line);
process.exit();
});
/**
*
* @param {string} line
*/
const main = (line) => {
const numbers = line.split("");
let answer = "";
numbers.forEach((str, i) => {
const dex = parseInt(str, 8);
let binary = dex.toString(2);
while (i !== 0 && binary.length < 3) {
binary = "0" + binary;
}
answer += binary;
});
console.log(answer);
};
문자열이 너무 커서, 아무래도 틀렸던 모양이다.
그래서 저번처럼 8진수에서 2진수로 변환하기 위해서 한 자리씩 차례대로 변경해서 합쳐주는 식으로 하였다.
진법 변환이라는 키워드보단, 자바스크립트에서는 parseInt와 toString 문제라고 생각하는 게 편할 거 같다.
오늘은 이걸 포함해 현재 6문제 째 풀었다. ( 너무 쉬운 문제들이라 굳이 포스팅하지 않았다. )
반응형
'프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
[node.js] 연결 요소의 개수 ( 백준 11724번 ) (0) | 2021.04.09 |
---|---|
[node.js] dfs와 bfs ( 백준 1260번 ) (0) | 2021.04.09 |
[node.js] ABCDE ( 백준 13023번 ) (0) | 2021.04.08 |
[node.js] 배수 찾기 ( 백준 4504번 ) (0) | 2021.04.08 |
[node.js] 피보나치 수 ( 백준 2747번 ) (0) | 2021.04.08 |