n进制到10进制可以有两种转换思路:一种是乘n加余,一种是a*(n^k)累加
#include <iostream>
#include "stack"
#include "cmath"
using namespace std;
int charToInt(char c) {
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
else if (c >= 'A' && c <= 'F') return c - 'A' + 10;
else return c - '0';
}
int main() {
string a;
while (cin >> a ) { // 注意 while 处理多个 case
// cout << b << endl;
long long result = 0;
for (int j = 2; j < a.size(); j++) {
// int remain = charToInt(a[j]);
// result *= 16;
// result += remain;
result+=charToInt(a[j])*pow(16,a.size()-j-1);
}
cout << result << endl;
}
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号