Algorithm/Problem Solving
2020. 4. 27. 23:06
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/11005
사용 알고리즘
-
풀이
- N이 0이 될 때까지 B로 나누며 나머지를 계속해서 구함
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/11005.cpp
#include <cstdio>
#include <vector>
using namespace std;
int main(void) {
int n, b; scanf("%d %d", &n, &b);
vector<int> v;
while (1) {
if (n == 0) break;
v.push_back(n % b);
n /= b;
}
int len = v.size();
for (int i = len - 1; i >= 0; --i) {
if (v[i] >= 0 && v[i] <= 9) printf("%d", v[i]);
else printf("%c", v[i] + 55);
}
printf("\n");
return 0;
}
|
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/1373] 2진수 8진수 (0) | 2020.05.11 |
---|---|
[BOJ/2745] 진법 변환 (0) | 2020.04.29 |
[BOJ/9613] GCD 합 (0) | 2020.04.23 |
[BOJ/1934] 최소공배수 (0) | 2020.04.23 |
[BOJ/2609] 최대공약수와 최소공배수 (0) | 2020.04.23 |