题解 | #进制转换#

进制转换

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

while True:
    try:
        s = input().strip()[2:]
        N = len(s)

        res = 0
        for i, c in enumerate(s):
            num = 0
            if c.isalpha():
                num = ord(c) - 55
            if c.isdigit():
                num = int(c)
            res += num * (16**(N-i-1))
        print(res)
    except:
        break

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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