题解 | #进制转换#

进制转换

https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6

#include <iostream>
#include<map>
#include <utility>
#include<math.h>
using namespace std;

map<char,int> m={{'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},{'a',10},{'b',11},{'c',12},
                {'d',13},{'e',14},{'f',15}};

int main() {
    string s;
    while(cin>>s)
    {
        int index=0,ans=0;
        for(int i=s.length()-1;i>1;i--)
        {
            ans=ans+m[s[i]]*pow(16,index);
            index++;
        }
        cout<<ans<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

有气魄的马来熊在摸鱼:我爱vivo 马上换手机 vivo我爱你!!!
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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