9.4滴滴笔试第二题题解python 100%


第二题,美丽数

def is_beauti(num, t):
    if num < 10:
        if num == t: return True
        else: return False
    hash_nums = [hash[c][::-1] for c in str(num)]
    hash_t = "{0:b}".format(t)
    for index, cur in enumerate(hash_t[::-1]):
        nums_cur = [each[index] for each in hash_nums]
        if cur == '1':
            if len(set(nums_cur)) != 2:
                return False
        else:
            if len(set(nums_cur)) != 1:
                return False
    return True

def beauti_count(l, r, t):
    count = 0
    for num in range(l, r+1):
        if is_beauti(num, t, ):
            count += 1
    return count

T = int(input())
left = list(map(int, input().split()))
right = list(map(int, input().split()))
nums = list(map(int, input().split()))
result = []
hash = {'0':'0000', '1':'0001', '2':'0010', '3':'0011', '4':'0100', '5':'0101', '6':'0110', '7':'0111', '8':'1000', '9':'1001'}
for l, r, t in zip(left, right, nums):
    count = beauti_count(l, r, t)
    print(count)


全部评论
hi~同学,秋招遇“寒气”,牛客送温暖啦!23届秋招笔面经有奖征集中,参与就得牛客会员7天免费体验,最高赢300元京东卡!戳我去看>>>https://www.nowcoder.com/link/zhengjipinglun
点赞 回复 分享
发布于 2022-09-05 13:21 北京

相关推荐

兄弟们你们进大厂靠的是什么项目啊
DOTPHTP:课设改。其实项目什么的如果不是实习里面的生产项目的话,建议✍️那种自己想要做的。突出个人自驱力,而不是为了找工作不得不随波逐流这种
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

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