-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10473.cpp
48 lines (42 loc) · 909 Bytes
/
10473.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
void tran(int x)
{
if (x / 16 > 0) tran(x / 16);
x %= 16;
if (x < 10)
printf("%d", x);
else
printf("%c", (char)('A' + x - 10));
}
int main(void)
{
int n, i, map[130];
char str[30];
for (i = 0; i < 10; ++i)
map[(int)'0' + i] = i;
for (i = 0; i < 6; ++i)
map[(int)'A' + i] = 10 + i;
while (true) {
scanf("%s", str);
if (str[0] == '-')
break;
else if (str[0] == '0' && str[1] == 'x') {
n = map[str[2]];
for (i = 3; i < strlen(str); ++i) {
n *= 16;
n += map[str[i]];
}
printf("%d\n", n);
}
else {
n = atoi(str);
printf("0x");
tran(n);
printf("\n");
}
}
return 0;
}