-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy path6.3.cpp
More file actions
38 lines (33 loc) · 754 Bytes
/
6.3.cpp
File metadata and controls
38 lines (33 loc) · 754 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
/*
* 题目名称:进制转换
* 题目来源:北京大学复试上机题
* 题目链接:http://t.cn/AiCuig9B
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int CharToInt(char c) { //字符变成数字
if ('0' <= c && c <= '9') {
return c - '0';
} else {
return c - 'A' + 10;
}
}
void Convert(string str, int x) { //x进制转换10进制
int number = 0;
for (int i = 0; i < str.size(); ++i) {
number *= x;
number += CharToInt(str[i]);
}
printf("%d\n", number);
}
int main() {
string str;
while (cin >> str) {
str = str.substr(2);
Convert(str, 16);
}
return 0;
}