#include<iostream> #include<string> #include<cmath> #include<unordered_map> using namespace std; int main() { string s; unordered_map<char, int> map = {{'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'A', 10}, {'B', 11}, {'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}}; while (cin >> s) { int ans = 0; // 此处一定要初始化 int len = s.size(); for (int i = len - 1, j = 0; s[i] != 'x'; --i, j++) { ans += map[s[i]] * pow(16, j); // pow的头文件是cmath } cout << ans << endl; } return 0; }