반응형
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2375&sca=99&sfl=wr_hit&stx=3106
JUNGOL
www.jungol.co.kr
#include <stdio.h>
typedef unsigned long long int u64;
u64 N, R;
char iv[66];
int cnt, A, B;
int bin[64];
char Hex[37] = { '0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z' };
bool input()
{
scanf("%d ", &A);
if (A == 0) return false;
scanf("%s %d ", iv, &B);
cnt = R = N = 0;
return true;
}
void MakeDecimal()
{
u64 cipher = 1;
int digit = 0;
for (cnt = 0; iv[cnt] != 0; cnt++) {}
for (int i = cnt - 1; i >= 0; i--)
{
if (iv[i] >= 'A') digit = iv[i] - 'A' + 10;
else digit = iv[i] - '0';
N += cipher * digit;
cipher *= A;
}
}
int main(void)
{
while (input())
{
MakeDecimal();
cnt = 63;
if (N == 0) { printf("0\n"); continue; }
while (N)
{
R = N % B;
N /= B;
bin[cnt--] = R;
}
for (int i = cnt + 1; i < 64; i++)
{
printf("%c", Hex[bin[i]]);
}
printf("\n");
}
return 0;
}
반응형
'프로그래밍 알고리즘' 카테고리의 다른 글
[정올 3123] 키로거(Keylogger) (0) | 2023.01.10 |
---|---|
[정올 3115] 긴 자리 나눗셈 (0) | 2023.01.10 |
[정올 3101] 요세푸스 문제1 (0) | 2023.01.09 |
[정올 2815] 10진수를 2진수로 (0) | 2023.01.09 |
[정올 2811] 소수와 합성수 (0) | 2023.01.09 |