题解 | #进制转换#

进制转换

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

#include <iostream>
using namespace std;

int main() {
    string str;
    getline(cin,str);
    int len=str.size();
    int base=1;
    int intValue=0;
    for(int i=len-1;i>1;i--){
        char ch=str[i];
        int chValue;
        if(ch>='0'&&ch<='9'){
            chValue=ch-'0';
        }else if(ch>='A'&&ch<='F'){
            chValue=ch-'A'+10;
        }else if(ch>='a'&&ch<='f'){
            chValue=ch-'a'+10;
        }
        intValue+=chValue*base;
        base*=16;
    }
    cout<<intValue;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
06-18 13:28
已编辑
门头沟学院 Web前端
爱睡觉的冰箱哥:《给予你300的工资》,阴的没边了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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