题解 | #进制转换#

进制转换

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

#include <iostream>
#include <string>
#include <cmath>

int main(int argc, char* argv[]){
    std::string str;
    std::cin >> str;
    int res = 0;
    int i = 0;
    int j = str.size() - 1;
    while(str[j] != 'x'){
        int num;
        if(str[j] >= '0' && str[j] <= '9'){
            num = str[j] - '0';
        }
        else {
            num = str[j] - 55;
        }
        res += pow(16, i) * num;
        --j;
        ++i;
    }
    std::cout << res <<std::endl;
    return 0;
}
全部评论

相关推荐

白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 14:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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