华为编程题十六进制转十进制
C++代码实现:
#include<iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
string s;
int temp = 0;
int Dec = 0;
while (getline(cin,s))
{
int len = s.length();
for (int i = 2; i < len;i++)
{
if (s[i] >= '0'&&s[i] <= '9')
{
Dec += ((s[i]-48)*pow(16, (len - 1 - i)));
}
if (toupper(s[i]) >= 'A'&&toupper(s[i]) <= 'Z')
{
Dec += (toupper(s[i]-55)*pow(16, (len - 1 - i)));
}
}
cout << Dec << endl;
Dec = 0;
}
system("pause");
return 0;
}