Submission
Status:
PP-PPPPPPP
Score: 90
User: tankunkid
Problemset: แปลงเลขฐาน
Language: c
Time: 0.001 second
Submitted On: 2024-10-16 21:23:14
#include <stdio.h>
int main(void) {
long base10 = 0, base2 = 0, base8 = 0;
char base16[4];
scanf("%s", base16);
for (int i = 0; base16[i] != '\0'; i++)
{
base10 *= 16;
if (base16[i] >= '0' && base16[i] <= '9')
base10 += base16[i] - 48;
else if (base16[i] >= 'A' && base16[i] <= 'F')
base10 += base16[i] - 55;
}
int digit2 = 1, digit8 = 1;
while (digit2 < base10/2)
digit2 *= 2;
while (digit8 < base10/8)
digit8 *= 8;
long anotherbase10 = base10;
while (digit2 != 0)
{
printf("%d", base10 / digit2);
base10 -= (base10 / digit2) * digit2;
digit2 /= 2;
}
printf("\n");
while (digit8 != 0)
{
printf("%d", anotherbase10 / digit8);
anotherbase10 -= (anotherbase10 / digit8) * digit8;
digit8 /= 8;
}
}