题解 | 九倍平方数

九倍平方数

https://www.nowcoder.com/practice/032c72fab5fe4a2ea8e11d40378a493d

n = int(input())
while True:
    try:
        n = input()
        s = 0
        shu2 = 0
        shu3 = 0
        for i in n:
            s += int(i)
            if i == '2':
                shu2 += 1
            elif i == '3':
                shu3 += 1
        g = 0
        if s % 9 == 0:
            g += 1
        else:
            y = s % 9
            if y == 7 :
                if shu2 >= 1:
                    g += 1
            elif y == 5 :
                if shu2 >= 2:
                    g += 1
            elif y == 3 :
                if shu2 >= 3 or shu3 >= 1:
                    g += 1
            elif y == 1 :
                if shu2 >= 4 or (shu3 >= 1 and shu2 >= 1):
                    g += 1
            elif y == 8:
                if shu2 >= 5 or (shu3 >= 1 and shu2 >= 2):
                    g += 1
            elif y == 6:
                if shu2 >= 6 or (shu3 >= 1 and shu2 >= 3) or shu3 >= 2:
                    g += 1
            elif y == 4:
                if shu2 >= 7 or (shu3 >= 1 and shu2 >= 4) or (shu3 >= 2 and shu2 >= 1):
                    g += 1
            elif y == 2:
                if shu2 >= 8 or (shu3 >= 1 and shu2 >= 5) or (shu3 >= 2 and shu2 >= 2):
                    g += 1
        if g == 0:
            print('NO')
        else:
            print('YES')
    except:
        break

全部评论

相关推荐

点赞 评论 收藏
分享
在改简历的大卫很认真:天天有面试 = 你已经在 offer 门口了。 海投能面成这样,说明你的简历、基础、学历都是过关的,缺的只是一次刚好匹配的缘分。 关于你说的 SQL 恐惧,我帮你捋一下: - 面试里考来考去,真就那几类: 分组、去重、关联、子查询、窗口函数(row_number、rank、sum 开窗) ​ - 面试官要的不是“写得花里胡哨”,而是思路稳、不出错。 你恐惧的本质不是不会, 是怕临场卡壳、怕写错、怕被追问。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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