问题描述
从键盘输入一个不超过8位的正的十六进制数字符串,将它转换为正的十进制数后输出。
注:十六进制数中的10~15分别用大写的英文字母A、B、C、D、E、F表示。
注:十六进制数中的10~15分别用大写的英文字母A、B、C、D、E、F表示。
样例输入
FFFF
样例输出
65535
#include<memory>
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<sstream>
using namespace std;
bool to16_10(std::string& word ){
long long count = 0;
for (unsigned int var1 = 0; var1 < word.length (); ++var1) {
if(word.at(var1) >= '0' && word.at (var1) <= '9'){
count = 16*count + (word.at (var1) - '0');
}
else if(word.at(var1) >= 'A' && word.at (var1) <= 'F'){
count = 16*count + (word.at (var1) - 'A'+10);
}
}
std::stringstream ss;
ss << count;
ss >> word;
return true;
}
int main(int argc, char *argv[])
{
string word;
cin >> word;
to16_10 (word);
cout <<word <<endl;
return 0;
}