简单
#include <iostream> #include <string> #include <map> #include <cmath> using namespace std; int main() { string s; map<char, int> m; for(int i=0; i<10; i++){ m['0' + i] = i; } m['A'] = 10; m['B'] = 11; m['C'] = 12; m['D'] = 13; m['E'] = 14; m['F'] = 15; while(cin >> s) { int re = 0; for(int i=s.size() - 1; i>1; i--){ re = re + m[s[i]] * pow(16, (s.size() - i - 1)); } cout << re << endl; } }