#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string s;
while (cin >> s) {
int len = s.length()-2; //去掉开始输入的'0'与'X'
int temp = 0;
int D = 0;
for (int i = 2; i < len+2; i++) {
switch (s[i])
{
case 'A': temp = 10; break;
case 'B': temp = 11; break;
case 'C': temp = 12; break;
case 'D': temp = 13; break;
case 'E': temp = 14; break;
case 'F': temp = 15; break;
default: temp = s[i] - '0'; break;
}
D += (temp * pow(16, len + 1 - i));
}
cout << D << endl;
}
return 0;
}
刷题05:华为机试 HJ5
最新推荐文章于 2023-07-19 15:54:08 发布