题解 | #进制转换# C++ 哈希表解决
进制转换
http://www.nowcoder.com/questionTerminal/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <unordered_map>
using namespace std;
const int N = 100010;
unordered_map<char, int> tab={{'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}};
int main() {
string str;
while (cin >> str&&!str.empty()) { // 注意 while 处理多个 case
int ans = 0;
for(int i = 0 ;i<str.size();++i)
ans = ans *16 + tab[tolower(str[i])];
cout << ans;
}
}
// 64 位输出请用 printf("%lld")
