题解 | 记数问题

记数问题

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

n,x=map(int,input().split())
count=0
target=str(x)
for i in range(1,n+1):
        count+=str(i).count(target)
print(count)

主要要注意不能用if来看某个数字中是否含有x,然后利用count+=1,这样算的话,如果某个字符含有多个x,也只记录了一次。

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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