티스토리 뷰

https://www.acmicpc.net/problem/11005

 

11005번: 진법 변환 2

10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를

www.acmicpc.net

const fs = require('fs');
let [N,B] = fs.readFileSync("./dev/stdin").toString().trim().split(' ').map(Number);
let answer = '';


if(N==0){
  console.log(0)
}else{ 
  while(N>0){
    let s = notation(N%B);
    answer = s+answer;
    N = Math.floor(N/B)
  }
  console.log(answer)
}


function notation(x){
  if(x<10) return x;
  return String.fromCharCode(x+55)
}
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함