#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ZERO 48
#define A 65
#define SIZE 100

int main()
{
    /* Declare variables */
    int DECIMAL;
    int BASE;
    char ans[SIZE];

    int remainder;
    int idx;
    int i;

    /* Initiallize variables */
    memset(ans, '\0', SIZE);
    idx = 0;

    /* Get input */
    scanf("%d", &DECIMAL);
    scanf("%d", &BASE);
    
    while (DECIMAL > 0)
    {
        remainder = (DECIMAL % BASE);
        if (remainder < 10)
        {
            remainder += ZERO;
        }
        else{
            remainder += A - 10;
        }
        ans[idx] = (char)remainder;
        idx++;
        DECIMAL = DECIMAL / BASE;
    }

    for (i = 0; i < idx; i++)
    {
        printf("%c",ans[idx - i - 1]);
    }
    printf("\n");

}

'코딩테스트 > C' 카테고리의 다른 글

백준 2720 세탁소 사장 동혁  (1) 2024.07.14
백준 2745 진법 변환  (0) 2024.07.14
백준 2563 색종이  (0) 2024.07.13
백준 10798 세로 읽기  (0) 2024.07.13
백준 2566 최댓값  (0) 2024.07.13

+ Recent posts