题解 | #进制转换#先做个哈希表比较好弄

进制转换

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;
}
全部评论

相关推荐

06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
把实习生当正职使昨天第一天就加班,晚上连口饭都没吃上,以后日子咋过,我不想干了
码农索隆:实习不怕忙,就怕干的活重复且没难度,要干就干那种有深度有难度的任务,这样才能快速的提升
实习吐槽大会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务