2745번 - 진법 변환
#include
int main() {
char a[10001];
int b;
scanf("%s", a);
scanf("%d", &b);
int i = 0;
long int decimal=0;
int position=1;
while (a[i] != '\0') {
if (a[i] >= 'A' && a[i] <= 'Z') {
if (a[i] == 'A')
decimal += 10*position;
else if (a[i] == 'B')
decimal += 11*position;
else if (a[i] == 'C')
decimal += 12*position;
else if (a[i] == 'D')
decimal += 13*position;
else if (a[i] == 'E')
decimal += 14*position;
else if (a[i] == 'F')
decimal += 15*position;
else if (a[i] == 'G')
decimal += 16*position;
else if (a[i] == 'H')
decimal += 17*position;
else if (a[i] == 'I')
decimal += 18*position;
else if (a[i] == 'J')
decimal += 19*position;
else if (a[i] == 'K')
decimal += 20*position;
else if (a[i] == 'L')
decimal += 21*position;
else if (a[i] == 'M')
decimal += 22*position;
else if (a[i] == 'N')
decimal += 23*position;
else if (a[i] == 'O')
decimal += 24*position;
else if (a[i] == 'P')
decimal += 25*position;
else if (a[i] == 'Q')
decimal += 26*position;
else if (a[i] == 'R')
decimal += 27*position;
else if (a[i] == 'S')
decimal += 28*position;
else if (a[i] == 'T')
decimal += 29*position;
else if (a[i] == 'U')
decimal += 30*position;
else if (a[i] == 'V')
decimal += 31*position;
else if (a[i] == 'W')
decimal += 32*position;
else if (a[i] == 'X')
decimal += 33*position;
else if (a[i] == 'Y')
decimal += 34*position;
else if (a[i] == 'Z')
decimal += 35*position;
} else {
decimal += (a[i]-'0')*position;
}
i++;
position *=b;
printf("%ld\n",decimal);
계산 방향이 반대입니다.
반례1100 2
감사합니다!
댓글을 작성하려면 로그인해야 합니다.
scg9767 2년 전
#include
#include
#include
int main() {
char a[10001];
int b;
scanf("%s", a);
scanf("%d", &b);
int i = 0;
long int decimal=0;
int position=1;
while (a[i] != '\0') {
if (a[i] >= 'A' && a[i] <= 'Z') {
if (a[i] == 'A')
decimal += 10*position;
else if (a[i] == 'B')
decimal += 11*position;
else if (a[i] == 'C')
decimal += 12*position;
else if (a[i] == 'D')
decimal += 13*position;
else if (a[i] == 'E')
decimal += 14*position;
else if (a[i] == 'F')
decimal += 15*position;
else if (a[i] == 'G')
decimal += 16*position;
else if (a[i] == 'H')
decimal += 17*position;
else if (a[i] == 'I')
decimal += 18*position;
else if (a[i] == 'J')
decimal += 19*position;
else if (a[i] == 'K')
decimal += 20*position;
else if (a[i] == 'L')
decimal += 21*position;
else if (a[i] == 'M')
decimal += 22*position;
else if (a[i] == 'N')
decimal += 23*position;
else if (a[i] == 'O')
decimal += 24*position;
else if (a[i] == 'P')
decimal += 25*position;
else if (a[i] == 'Q')
decimal += 26*position;
else if (a[i] == 'R')
decimal += 27*position;
else if (a[i] == 'S')
decimal += 28*position;
else if (a[i] == 'T')
decimal += 29*position;
else if (a[i] == 'U')
decimal += 30*position;
else if (a[i] == 'V')
decimal += 31*position;
else if (a[i] == 'W')
decimal += 32*position;
else if (a[i] == 'X')
decimal += 33*position;
else if (a[i] == 'Y')
decimal += 34*position;
else if (a[i] == 'Z')
decimal += 35*position;
} else {
decimal += (a[i]-'0')*position;
}
i++;
position *=b;
}
printf("%ld\n",decimal);
}