题解 | 九倍平方数
九倍平方数
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

