-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path0005.cpp
More file actions
40 lines (37 loc) · 687 Bytes
/
0005.cpp
File metadata and controls
40 lines (37 loc) · 687 Bytes
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
// 0005.进制转换
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int turn(int c)
{
int a = toupper(c);
if(a >= 'A' && a <= 'Z')
{
return a - 'A' + 10;
}
else {
return a - '0';
}
}
int main()
{
char a[100];
while(cin.getline(a, 100))
{
int sum = 0;
reverse(a, a + strlen(a));
for(int i = 0; i < strlen(a); i++)
{
if (toupper(a[i]) == 'X') break;
int t = turn(a[i]);
for(int j = 0; j < i; j++)
{
t *= 16;
}
sum += t;
}
cout << sum << endl;
}
return 0;
}