题解 | #进制A+B#

进制A+B

https://www.nowcoder.com/practice/6187581174ac48278ca3bccf8d534897

#include <iostream>
#include <string>
#include <cstdlib>

int hexToDec(const std::string& hexStr) {
    return std::strtol(hexStr.c_str(), NULL, 16);
}

int octToDec(const std::string& octStr) {
    return std::strtol(octStr.c_str(), NULL, 8);
}

int main() {
    std::string hex, oct;
    std::cin >> hex >> oct;

    int decimalSum = hexToDec(hex) + octToDec(oct);

    std::cout << decimalSum << std::endl;

    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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