题解 | #进制转换#先做个哈希表比较好弄
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<queue>
#include<list>
#include<cctype>
#include<unordered_map>
#include<unordered_set>
#define ___ "-------------------------------\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 100000 + 5;
unordered_map<char, int> mp = {
{'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(){
// ios::sync_with_stdio(false);
// ifstream cin("data.txt");
// freopen("data.txt", "r", stdin);
string s;
cin >> s;
int base = 1;
int ans = 0;
for(int i = s.length() - 1; s[i] != 'x'; i--){
ans += mp[s[i]] * base;
base *= 16;
}
cout << ans << endl;
return 0;
}