题解 | 九倍平方数

九倍平方数

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

全部评论

相关推荐

01-12 17:45
门头沟学院 Java
叁六玖:这样的应该钱不多,以前我也被问,我在问他们实习公工资多少,一般都是2200-2800
找实习记录
点赞 评论 收藏
分享
2025-12-16 17:17
门头沟学院 产品经理
烤点老白薯:他第二句话的潜台词是想让你帮他点个瑞幸或者喜茶啥的
mt对你说过最有启发的一...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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