题解 | 记数问题

记数问题

https://www.nowcoder.com/practice/28b2d9f2bf2c48de94a1297ed90e1732

n, m = map(int, input().split())
count = 0
m_str = str(m)

for i in range(1, n + 1):
    num_str = str(i)
    occurrences = num_str.count(m_str)
    if occurrences > 0:
        count += occurrences

print(count)
'''
错在没有考虑22,33,44这种数字
n, m = map(int, input().split())
count = 0
c=[]
for i in range(1, n + 1):
    if str(m) in str(i):  # 把数字转为字符串后检查包含关系
        count += 1
        c.append(i)

print(count)
print(c)
'''

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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