题解 | #[NOIP2010]数字统计#
[NOIP2010]数字统计
https://www.nowcoder.com/practice/179d9754eeaf48a1b9a49dc1d438525a
def count_num2_and_list(L, R):
count = 0 # 设置计数器
res_list = [] # 设置结果列表
for i in range(L, R+1):
str_i = str(i) # 将数字转换成字符串
if '2' in str_i: # 判断字符串中是否包含数字2
count += str_i.count('2') # 计算字符串中2的个数,并累加到计数器中
res_list.append(i) # 记录包含数字2的数字
return count, res_list
a, b = map(int, input().split())
count1, rs1 = count_num2_and_list(a, b)
print (count1)
# print (rs1)