1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<cstdio> #include<string> #include<iostream> #include<algorithm> using namespace std; int main(void) { int n,b; scanf("%d %d", &n,&b); string sstr; while(n>0) { int r=n%b; if(r<10) sstr+=(char)(r+'0'); else sstr+=(char)(r-10+'A'); n/=b; } reverse(sstr.begin(), sstr.end()); cout<<sstr<<'\n'; return 0; } | cs |
10진법 수 N을 B진법으로 바꾸기 위해 N이 0이 될 때까지 나머지를 계속해서 구한다
'백준 1 > 수학' 카테고리의 다른 글
| [백준 11653] 소인수 분해 (0) | 2020.12.06 |
|---|---|
| [백준 1978] 소수 찾기 (0) | 2020.12.06 |
| [백준 2745] 진법 변환 (0) | 2020.12.05 |
| [백준 9613] GCD 합 (0) | 2020.12.05 |
| [백준 1934] 최소공배수 (0) | 2020.12.05 |