#include <iostream>
#include <string>
#include <vector>
#include <cmath>
int hex2int(const std::string &hex) {
std::string::const_reverse_iterator rit=hex.rbegin();
int i=0, ret=0;
for(; rit!=hex.rend(); ++rit) {
if(*rit >= '0' && *rit <= '9') {
ret += (*rit - '0') * pow(16, i);
}
else if(*rit >= 'a' && *rit <= 'f') {
ret += (*rit - 'a' + 10) * pow(16, i);
}
else {
ret += (*rit - 'A' + 10) * pow(16, i);
}
i++;
}
return ret;
}
int main() {
std::vector<std::string> v_s;
v_s.push_back("12a");
v_s.push_back("ef");
v_s.push_back("a1");
v_s.push_back("2a3");
v_s.push_back("A1");
for(std::vector<std::string>::const_iterator cit=v_s.begin(); cit!=v_s.end(); ++cit) {
std::cout<<"16进制: "<<*cit<<" 10进制: "<<hex2int(*cit)<<std::endl;
}
return 0;
}